浏览代码

Made add() chainable.

Piotrek Koszuliński 10 年之前
父节点
当前提交
847195594b

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

@@ -77,6 +77,7 @@ CKEDITOR.define( [ 'emittermixin', 'ckeditorerror', 'utils' ], function( Emitter
 		 *
 		 * If the item does not have an id, then it will be automatically generated and set on the item.
 		 *
+		 * @chainable
 		 * @param {Object} item
 		 */
 		add( item ) {
@@ -112,6 +113,8 @@ CKEDITOR.define( [ 'emittermixin', 'ckeditorerror', 'utils' ], function( Emitter
 			this._itemMap.set( itemId, item );
 
 			this.fire( 'add', item );
+
+			return this;
 		}
 
 		/**

+ 6 - 0
packages/ckeditor5-utils/tests/collection/collection.js

@@ -41,6 +41,12 @@ describe( 'constructor', () => {
 } );
 
 describe( 'add', () => {
+	it( 'should be chainable', () => {
+		var box = getCollection();
+
+		expect( box.add( {} ) ).to.equal( box );
+	} );
+
 	it( 'should change the length', () => {
 		var box = getCollection();