浏览代码

Changed: core.Command#checkEnabled to core.Command#refreshState.

Szymon Cofalik 9 年之前
父节点
当前提交
8084e02172
共有 2 个文件被更改,包括 23 次插入23 次删除
  1. 8 8
      packages/ckeditor5-engine/src/command.js
  2. 15 15
      packages/ckeditor5-engine/tests/command.js

+ 8 - 8
packages/ckeditor5-engine/src/command.js

@@ -22,10 +22,10 @@ export default class Command {
 		this.editor = editor;
 		this.isEnabled = true;
 
-		// If schema checking function is specified, add it to the `checkEnabled` listeners.
+		// If schema checking function is specified, add it to the `refreshState` listeners.
 		// Feature will be disabled if it does not apply to schema requirements.
 		if ( this.checkSchema ) {
-			this.on( 'checkEnabled', ( evt ) => {
+			this.on( 'refreshState', ( evt ) => {
 				if ( !this.checkSchema() ) {
 					evt.stop();
 
@@ -35,18 +35,18 @@ export default class Command {
 		}
 	}
 
-	checkEnabled() {
-		this.isEnabled = this.fire( 'checkEnabled' ) !== false;
+	refreshState() {
+		this.isEnabled = this.fire( 'refreshState' ) !== false;
 	}
 
 	_disable() {
-		this.on( 'checkEnabled', disableCallback );
-		this.checkEnabled();
+		this.on( 'refreshState', disableCallback );
+		this.refreshState();
 	}
 
 	_enable() {
-		this.off( 'checkEnabled', disableCallback );
-		this.checkEnabled();
+		this.off( 'refreshState', disableCallback );
+		this.refreshState();
 	}
 
 	execute() {

+ 15 - 15
packages/ckeditor5-engine/tests/command.js

@@ -44,49 +44,49 @@ describe( 'constructor', () => {
 		} ).not.to.throw;
 	} );
 
-	it( 'should add listener to its checkEnabled event if checkSchema method is present', () => {
+	it( 'should add listener to its refreshState event if checkSchema method is present', () => {
 		expect( command.checkSchema ).to.be.undefined;
 
 		command.checkSchema = sinon.spy();
-		command.checkEnabled();
+		command.refreshState();
 
 		expect( command.checkSchema.called ).to.be.false;
 
 		let newCommand = new CommandWithSchema( editor, true );
 		sinon.spy( newCommand, 'checkSchema' );
 
-		newCommand.checkEnabled();
+		newCommand.refreshState();
 
 		expect( newCommand.checkSchema.calledOnce ).to.be.true;
 	} );
 } );
 
-describe( 'checkEnabled', () => {
-	it( 'should fire checkEnabled event', () => {
+describe( 'refreshState', () => {
+	it( 'should fire refreshState event', () => {
 		let spy = sinon.spy();
 
-		command.on( 'checkEnabled', spy );
-		command.checkEnabled();
+		command.on( 'refreshState', spy );
+		command.refreshState();
 
 		expect( spy.called ).to.be.true;
 	} );
 
 	it( 'should set isEnabled property to the value returned by last event callback', () => {
-		command.on( 'checkEnabled', () => {
+		command.on( 'refreshState', () => {
 			return true;
 		} );
 
-		command.on( 'checkEnabled', ( evt ) => {
+		command.on( 'refreshState', ( evt ) => {
 			evt.stop();
 
 			return false;
 		} );
 
-		command.on( 'checkEnabled', () => {
+		command.on( 'refreshState', () => {
 			return true;
 		} );
 
-		command.checkEnabled();
+		command.refreshState();
 
 		expect( command.isEnabled ).to.be.false;
 	} );
@@ -94,7 +94,7 @@ describe( 'checkEnabled', () => {
 	it( 'should set isEnabled to false if checkSchema returns false', () => {
 		let disabledCommand = new CommandWithSchema( editor, false );
 
-		disabledCommand.checkEnabled();
+		disabledCommand.refreshState();
 
 		expect( disabledCommand.isEnabled ).to.be.false;
 	} );
@@ -108,7 +108,7 @@ describe( 'disable', () => {
 	} );
 
 	it( 'should not make command disabled if there is a high-priority listener forcing command to be enabled', () => {
-		command.on( 'checkEnabled', ( evt ) => {
+		command.on( 'refreshState', ( evt ) => {
 			evt.stop();
 
 			return true;
@@ -131,13 +131,13 @@ describe( 'enable', () => {
 	it( 'should not make command enabled if there are other listeners disabling it', () => {
 		command._disable();
 
-		command.on( 'checkEnabled', ( evt ) => {
+		command.on( 'refreshState', ( evt ) => {
 			evt.stop();
 
 			return false;
 		} );
 
-		command.checkEnabled();
+		command.refreshState();
 		command._enable();
 
 		expect( command.isEnabled ).to.be.false;