Sfoglia il codice sorgente

Improved collection params.

Oskar Wróbel 8 anni fa
parent
commit
fcd1c220f5

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

@@ -28,10 +28,10 @@ export default class Collection {
 	/**
 	/**
 	 * Creates a new Collection instance.
 	 * Creates a new Collection instance.
 	 *
 	 *
-	 * @param {Object} options The options object.
+	 * @param {Object} [options={}] The options object.
 	 * @param {String} [options.idProperty='id'] The name of the property which is considered to identify an item.
 	 * @param {String} [options.idProperty='id'] The name of the property which is considered to identify an item.
 	 */
 	 */
-	constructor( options ) {
+	constructor( { idProperty = 'id' } = {} ) {
 		/**
 		/**
 		 * The internal list of items in the collection.
 		 * The internal list of items in the collection.
 		 *
 		 *
@@ -54,7 +54,7 @@ export default class Collection {
 		 * @private
 		 * @private
 		 * @member {String}
 		 * @member {String}
 		 */
 		 */
-		this._idProperty = options && options.idProperty || 'id';
+		this._idProperty = idProperty;
 
 
 		/**
 		/**
 		 * A helper mapping external items of a bound collection ({@link #bindTo})
 		 * A helper mapping external items of a bound collection ({@link #bindTo})

+ 1 - 1
packages/ckeditor5-utils/tests/collection.js

@@ -376,7 +376,7 @@ describe( 'Collection', () => {
 		} );
 		} );
 
 
 		it( 'should remove the model by model - custom id property', () => {
 		it( 'should remove the model by model - custom id property', () => {
-			const collection = new Collection( null, 'name' );
+			const collection = new Collection( { idProperty: 'name' } );
 			const item = getItem( 'foo', 'name' );
 			const item = getItem( 'foo', 'name' );
 
 
 			collection.add( item );
 			collection.add( item );