Browse Source

Added the "source" property to EventInfo.

fredck 10 years ago
parent
commit
124d7a0178

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

@@ -217,7 +217,7 @@ CKEDITOR.define( [ 'eventinfo', 'utils' ], function( EventInfo, utils ) {
 				return;
 			}
 
-			var eventInfo = new EventInfo( event );
+			var eventInfo = new EventInfo( this, event );
 
 			// Take the list of arguments to pass to the callbacks.
 			args = Array.prototype.slice.call( arguments, 1 );

+ 6 - 1
packages/ckeditor5-utils/src/eventinfo.js

@@ -13,7 +13,12 @@
  */
 
 CKEDITOR.define( [ 'utils' ], function( utils ) {
-	function EventInfo( name ) {
+	function EventInfo( source, name ) {
+		/**
+		 * The object that fired the event.
+		 */
+		this.source = source;
+
 		/**
 		 * The event name.
 		 */

+ 2 - 2
packages/ckeditor5-utils/src/mvc/model.js

@@ -80,8 +80,8 @@ CKEDITOR.define( [ 'emitter', 'utils' ], function( EmitterMixin, utils ) {
 
 					if ( oldValue !== value ) {
 						this._attributes[ name ] = value;
-						this.fire( 'change', this, name, value, oldValue );
-						this.fire( 'change:' + name, this, value, oldValue );
+						this.fire( 'change', name, value, oldValue );
+						this.fire( 'change:' + name, value, oldValue );
 					}
 				}
 			} );

+ 4 - 3
packages/ckeditor5-utils/tests/eventinfo/eventinfo.js

@@ -13,8 +13,9 @@ describe( 'EventInfo', function() {
 	it( 'should be created properly', function() {
 		var EventInfo = modules.eventinfo;
 
-		var event = new EventInfo( 'test' );
+		var event = new EventInfo( this, 'test' );
 
+		expect( event.source ).to.equals( this );
 		expect( event.name ).to.equals( 'test' );
 		expect( event.stop.called ).to.not.be.true();
 		expect( event.off.called ).to.not.be.true();
@@ -23,7 +24,7 @@ describe( 'EventInfo', function() {
 	it( 'should have cancel() and off() marked', function() {
 		var EventInfo = modules.eventinfo;
 
-		var event = new EventInfo( 'test' );
+		var event = new EventInfo( this, 'test' );
 
 		event.stop();
 		event.off();
@@ -35,7 +36,7 @@ describe( 'EventInfo', function() {
 	it( 'should not mark "called" in future instances', function() {
 		var EventInfo = modules.eventinfo;
 
-		var event = new EventInfo( 'test' );
+		var event = new EventInfo( this, 'test' );
 
 		event.stop();
 		event.off();

+ 6 - 6
packages/ckeditor5-utils/tests/mvc/model/model.js

@@ -105,12 +105,12 @@ describe( 'Model', function() {
 			sinon.assert.calledOn( spyWheels, car );
 
 			// Check params.
-			sinon.assert.calledWithExactly( spy, sinon.match.instanceOf( EventInfo ), car, 'color', 'blue', 'red' );
-			sinon.assert.calledWithExactly( spy, sinon.match.instanceOf( EventInfo ), car, 'year', 2003, 2015 );
-			sinon.assert.calledWithExactly( spy, sinon.match.instanceOf( EventInfo ), car, 'wheels', 4, sinon.match.typeOf( 'undefined' ) );
-			sinon.assert.calledWithExactly( spyColor, sinon.match.instanceOf( EventInfo ), car, 'blue', 'red' );
-			sinon.assert.calledWithExactly( spyYear, sinon.match.instanceOf( EventInfo ), car, 2003, 2015 );
-			sinon.assert.calledWithExactly( spyWheels, sinon.match.instanceOf( EventInfo ), car, 4, sinon.match.typeOf( 'undefined' ) );
+			sinon.assert.calledWithExactly( spy, sinon.match.instanceOf( EventInfo ), 'color', 'blue', 'red' );
+			sinon.assert.calledWithExactly( spy, sinon.match.instanceOf( EventInfo ), 'year', 2003, 2015 );
+			sinon.assert.calledWithExactly( spy, sinon.match.instanceOf( EventInfo ), 'wheels', 4, sinon.match.typeOf( 'undefined' ) );
+			sinon.assert.calledWithExactly( spyColor, sinon.match.instanceOf( EventInfo ), 'blue', 'red' );
+			sinon.assert.calledWithExactly( spyYear, sinon.match.instanceOf( EventInfo ), 2003, 2015 );
+			sinon.assert.calledWithExactly( spyWheels, sinon.match.instanceOf( EventInfo ), 4, sinon.match.typeOf( 'undefined' ) );
 		} );
 	} );