Преглед на файлове

Removed event-bubbling features.

fredck преди 10 години
родител
ревизия
10c97c8b0e

+ 13 - 54
packages/ckeditor5-utils/src/emitter.js

@@ -216,11 +216,9 @@ CKEDITOR.define( [ 'eventinfo', 'utils' ], function( EventInfo, utils ) {
 		fire: function( event, args ) {
 			var eventInfo = event instanceof EventInfo && event;
 			var eventName = eventInfo ? eventInfo.name : event;
-			var parents = this._parentEmitters;
-
 			var callbacks = getCallbacksIfAny( this, eventName );
 
-			if ( !callbacks && !parents ) {
+			if ( !callbacks ) {
 				return;
 			}
 
@@ -232,61 +230,22 @@ CKEDITOR.define( [ 'eventinfo', 'utils' ], function( EventInfo, utils ) {
 			args = Array.prototype.slice.call( arguments, 1 );
 			args.unshift( eventInfo );
 
-			if ( callbacks ) {
-				for ( var i = 0; i < callbacks.length; i++ ) {
-					callbacks[ i ].callback.apply( callbacks[ i ].ctx, args );
-
-					// Remove the callback from future requests if off() has been called.
-					if ( eventInfo.off.called ) {
-						// Remove the called mark for the next calls.
-						delete eventInfo.off.called;
-
-						// Remove the callback from the list (fixing the next index).
-						callbacks.splice( i, 1 );
-						i--;
-					}
+			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;
-					}
-				}
-			}
+				// Remove the callback from future requests if off() has been called.
+				if ( eventInfo.off.called ) {
+					// Remove the called mark for the next calls.
+					delete eventInfo.off.called;
 
-			// Fires the same event on all parents.
-			if ( parents ) {
-				for ( var e = 0; e < parents.length; e++ ) {
-					parents[ e ].fire.apply( parents[ e ], args );
+					// Remove the callback from the list (fixing the next index).
+					callbacks.splice( i, 1 );
+					i--;
 				}
-			}
-		},
-
-		/**
-		 * Adds a parent emitter to this object.
-		 *
-		 * A parent emitter fires the same events fired by its children.
-		 *
-		 * @param {Emitter} parentEmitter The parent to be added.
-		 */
-		addParentEmitter: function( parentEmitter ) {
-			if ( !this._parentEmitters ) {
-				this._parentEmitters = [];
-			}
-
-			this._parentEmitters.push( parentEmitter );
-		},
-
-		/**
-		 * Removes a parent emitter from this object.
-		 *
-		 * @param {Emitter} parentEmitter The parent to be removed.
-		 */
-		removeParentEmitter: function( parentEmitter ) {
-			if ( this._parentEmitters ) {
-				this._parentEmitters.splice( this._parentEmitters.indexOf( parentEmitter ), 1 );
 
-				if ( !this._parentEmitters.length ) {
-					delete this._parentEmitters;
+				// Do not execute next callbacks if stop() was called.
+				if ( eventInfo.stop.called ) {
+					break;
 				}
 			}
 		}

+ 0 - 3
packages/ckeditor5-utils/src/mvc/collection.js

@@ -53,8 +53,6 @@ CKEDITOR.define( [ 'emitter', 'utils' ], function( EmitterMixin, utils ) {
 		 * @param {Model} model The item to be added.
 		 */
 		add: function( model ) {
-			model.addParentEmitter( this );
-
 			this._models.push( model );
 
 			this.fire( 'add', model );
@@ -98,7 +96,6 @@ CKEDITOR.define( [ 'emitter', 'utils' ], function( EmitterMixin, utils ) {
 				throw 'Index not found';
 			}
 
-			removedModel.removeParentEmitter( this );
 			this.fire( 'remove', removedModel );
 
 			return removedModel;

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

@@ -412,54 +412,6 @@ describe( 'stopListening', function() {
 	} );
 } );
 
-describe( 'addParentEmitter', function() {
-	it( 'should propagate events to the parent', function() {
-		var parentEmitter = getEmitterInstance();
-		emitter.addParentEmitter( parentEmitter );
-
-		var parentSpy = sinon.spy();
-
-		parentEmitter.on( 'test', parentSpy );
-
-		emitter.fire( 'test', 'a' );
-		emitter.fire( 'test' );
-
-		sinon.assert.calledTwice( parentSpy );
-		sinon.assert.calledWithExactly( parentSpy, sinon.match.has( 'source', emitter ) , 'a' );
-		sinon.assert.calledWithExactly( parentSpy, sinon.match.has( 'source', emitter ) );
-	} );
-} );
-
-describe( 'removeParentEmitter', function() {
-	it( 'should stop propagating events to the parent', function() {
-		var parentEmitter = getEmitterInstance();
-		emitter.addParentEmitter( parentEmitter );
-
-		var parentSpy = sinon.spy();
-		var childSpy = sinon.spy();
-
-		parentEmitter.on( 'test', parentSpy );
-		emitter.on( 'test', childSpy );
-
-		emitter.fire( 'test' );
-
-		sinon.assert.calledOnce( parentSpy );
-		sinon.assert.calledOnce( childSpy );
-
-		emitter.removeParentEmitter( parentEmitter );
-
-		parentSpy.reset();
-		childSpy.reset();
-
-		emitter.fire( 'test' );
-
-		sinon.assert.notCalled( parentSpy );
-		sinon.assert.calledOnce( childSpy );
-
-		emitter.removeParentEmitter( parentEmitter );
-	} );
-} );
-
 function refreshEmitter() {
 	emitter = getEmitterInstance();
 }

+ 0 - 22
packages/ckeditor5-utils/tests/mvc/collection/collection.js

@@ -114,28 +114,6 @@ describe( 'remove', function() {
 	} );
 } );
 
-describe( 'on', function() {
-	it( 'should listen to child events', function() {
-		var box = getCollection();
-		var item1 = getItem();
-		var item2 = getItem();
-		var spy = sinon.spy();
-
-		box.add( item1 );
-		box.add( item2 );
-
-		box.on( 'item-event', spy );
-
-		item1.fire( 'item-event' );
-		item2.fire( 'item-event' );
-
-		sinon.assert.calledTwice( spy );
-		sinon.assert.alwaysCalledOn( spy, box );
-		sinon.assert.calledWithExactly( spy, sinon.match.has( 'source', item1 ) );
-		sinon.assert.calledWithExactly( spy, sinon.match.has( 'source', item2 ) );
-	} );
-} );
-
 function getCollection() {
 	var Collection = modules[ 'mvc/collection' ];