Browse Source

Moved the `stop()` check to the end of the callbacks look in `fire()` so other commands (like `save()`) get processed.

fredck 10 years ago
parent
commit
7a30d8b33f

+ 5 - 5
packages/ckeditor5-utils/src/emitter.js

@@ -225,11 +225,6 @@ CKEDITOR.define( [ 'eventinfo', 'utils' ], function( EventInfo, utils ) {
 			for ( var i = 0; i < callbacks.length; i++ ) {
 				callbacks[ i ].callback.apply( callbacks[ i ].ctx, args );
 
-				// Do not execute next callbacks if stop() was called.
-				if ( eventInfo.stop.called ) {
-					break;
-				}
-
 				if ( eventInfo.off.called ) {
 					// Remove the called mark for the next calls.
 					delete eventInfo.off.called;
@@ -238,6 +233,11 @@ CKEDITOR.define( [ 'eventinfo', 'utils' ], function( EventInfo, utils ) {
 					callbacks.splice( i, 1 );
 					i--;
 				}
+
+				// Do not execute next callbacks if stop() was called.
+				if ( eventInfo.stop.called ) {
+					break;
+				}
 			}
 		}
 	};

+ 17 - 0
packages/ckeditor5-utils/tests/emitter/emitter.js

@@ -161,6 +161,23 @@ describe( 'on', function() {
 		sinon.assert.calledOnce( spy2 );
 		sinon.assert.calledTwice( spy3 );
 	} );
+
+	it( 'should take the callback off() even after stop()', function() {
+		var spy1 = sinon.spy( function( event ) {
+			event.stop();
+			event.off();
+		} );
+		var spy2 = sinon.spy();
+
+		emitter.on( 'test', spy1 );
+		emitter.on( 'test', spy2 );
+
+		emitter.fire( 'test' );
+		emitter.fire( 'test' );
+
+		sinon.assert.calledOnce( spy1 );
+		sinon.assert.calledOnce( spy2 );
+	} );
 } );
 
 describe( 'once', function() {