Procházet zdrojové kódy

Internal (color): Simplified DocumentColorCollection class to use the new change event.

Marek Lewandowski před 5 roky
rodič
revize
ba2ae0e5c4

+ 5 - 15
packages/ckeditor5-font/src/documentcolorcollection.js

@@ -29,6 +29,10 @@ export default class DocumentColorCollection extends Collection {
 		 * @member {Boolean} #isEmpty
 		 * @member {Boolean} #isEmpty
 		 */
 		 */
 		this.set( 'isEmpty', true );
 		this.set( 'isEmpty', true );
+
+		this.on( 'change', () => {
+			this.set( 'isEmpty', this.length === 0 );
+		} );
 	}
 	}
 
 
 	/**
 	/**
@@ -44,6 +48,7 @@ export default class DocumentColorCollection extends Collection {
 	 * @param {Number} [index] The position of the item in the collection. The item
 	 * @param {Number} [index] The position of the item in the collection. The item
 	 * is pushed to the collection when `index` is not specified.
 	 * is pushed to the collection when `index` is not specified.
 	 * @fires add
 	 * @fires add
+	 * @fires change
 	 */
 	 */
 	add( item, index ) {
 	add( item, index ) {
 		if ( this.find( element => element.color === item.color ) ) {
 		if ( this.find( element => element.color === item.color ) ) {
@@ -52,21 +57,6 @@ export default class DocumentColorCollection extends Collection {
 		}
 		}
 
 
 		super.add( item, index );
 		super.add( item, index );
-
-		this.set( 'isEmpty', false );
-	}
-
-	/**
-	 * @inheritdoc
-	 */
-	remove( subject ) {
-		const ret = super.remove( subject );
-
-		if ( this.length === 0 ) {
-			this.set( 'isEmpty', true );
-		}
-
-		return ret;
 	}
 	}
 
 
 	/**
 	/**