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

Merge pull request #116 from ckeditor/t/113-b

T/113 b LivePosition, LiveRange and Selection
Piotr Jasiun преди 10 години
родител
ревизия
5c0ff1951b

+ 2 - 3
packages/ckeditor5-ui/.jscsrc

@@ -58,6 +58,5 @@
 	"disallowNewlineBeforeBlockStatements": true,
 	"disallowNewlineBeforeBlockStatements": true,
 	"validateLineBreaks": "LF",
 	"validateLineBreaks": "LF",
 	"validateQuoteMarks": "'",
 	"validateQuoteMarks": "'",
-	"validateIndentation": "\t",
-	"safeContextKeyword": [ "that" ]
-}
+	"validateIndentation": "\t"
+}

+ 0 - 4
packages/ckeditor5-ui/src/config.js

@@ -75,9 +75,7 @@ CKEDITOR.define( [ 'model', 'utils' ], ( Model, utils ) => {
 			}
 			}
 
 
 			// The target for this configuration is, for now, this object.
 			// The target for this configuration is, for now, this object.
-			//jscs:disable safeContextKeyword
 			let target = this;
 			let target = this;
-			//jscs:enable
 
 
 			// The configuration name should be split into parts if it has dots. E.g: `resize.width`.
 			// The configuration name should be split into parts if it has dots. E.g: `resize.width`.
 			const parts = name.toLowerCase().split( '.' );
 			const parts = name.toLowerCase().split( '.' );
@@ -131,9 +129,7 @@ CKEDITOR.define( [ 'model', 'utils' ], ( Model, utils ) => {
 		 */
 		 */
 		get( name ) {
 		get( name ) {
 			// The target for this configuration is, for now, this object.
 			// The target for this configuration is, for now, this object.
-			//jscs:disable safeContextKeyword
 			let source = this;
 			let source = this;
-			//jscs:enable
 
 
 			// The configuration name should be split into parts if it has dots. E.g. `resize.width` -> [`resize`, `width`]
 			// The configuration name should be split into parts if it has dots. E.g. `resize.width` -> [`resize`, `width`]
 			const parts = name.toLowerCase().split( '.' );
 			const parts = name.toLowerCase().split( '.' );

+ 15 - 1
packages/ckeditor5-ui/src/emittermixin.js

@@ -13,6 +13,10 @@
  */
  */
 
 
 CKEDITOR.define( [ 'eventinfo', 'utils' ], ( EventInfo, utils ) => {
 CKEDITOR.define( [ 'eventinfo', 'utils' ], ( EventInfo, utils ) => {
+	// Saves how many callbacks has been already added. Does not decrement when callback is removed.
+	// Used internally as a unique id for a callback.
+	let eventsCounter = 0;
+
 	const EmitterMixin = {
 	const EmitterMixin = {
 		/**
 		/**
 		 * Registers a callback function to be executed when an event is fired.
 		 * Registers a callback function to be executed when an event is fired.
@@ -35,7 +39,9 @@ CKEDITOR.define( [ 'eventinfo', 'utils' ], ( EventInfo, utils ) => {
 			callback = {
 			callback = {
 				callback: callback,
 				callback: callback,
 				ctx: ctx || this,
 				ctx: ctx || this,
-				priority: priority
+				priority: priority,
+				// Save counter value as unique id.
+				counter: ++eventsCounter
 			};
 			};
 
 
 			// Add the callback to the list in the right priority position.
 			// Add the callback to the list in the right priority position.
@@ -226,7 +232,15 @@ CKEDITOR.define( [ 'eventinfo', 'utils' ], ( EventInfo, utils ) => {
 			args = Array.prototype.slice.call( arguments, 1 );
 			args = Array.prototype.slice.call( arguments, 1 );
 			args.unshift( eventInfo );
 			args.unshift( eventInfo );
 
 
+			// Save how many callbacks were added at the moment when the event has been fired.
+			const counter = eventsCounter;
+
 			for ( let i = 0; i < callbacks.length; i++ ) {
 			for ( let i = 0; i < callbacks.length; i++ ) {
+				// Filter out callbacks that have been added after event has been fired.
+				if ( callbacks[ i ].counter > counter ) {
+					continue;
+				}
+
 				callbacks[ i ].callback.apply( callbacks[ i ].ctx, args );
 				callbacks[ i ].callback.apply( callbacks[ i ].ctx, args );
 
 
 				// Remove the callback from future requests if off() has been called.
 				// Remove the callback from future requests if off() has been called.

+ 12 - 0
packages/ckeditor5-ui/tests/emittermixin/emittermixin.js

@@ -118,6 +118,18 @@ describe( 'fire', () => {
 
 
 		sinon.assert.calledThrice( spy );
 		sinon.assert.calledThrice( spy );
 	} );
 	} );
+
+	it( 'should not fire callbacks for an event that were added while firing that event', () => {
+		let spy = sinon.spy();
+
+		emitter.on( 'test', () => {
+			emitter.on( 'test', spy );
+		} );
+
+		emitter.fire( 'test' );
+
+		sinon.assert.notCalled( spy );
+	} );
 } );
 } );
 
 
 describe( 'on', () => {
 describe( 'on', () => {