소스 검색

Made add() chainable.

Piotrek Koszuliński 10 년 전
부모
커밋
847195594b
2개의 변경된 파일9개의 추가작업 그리고 0개의 파일을 삭제
  1. 3 0
      packages/ckeditor5-utils/src/collection.js
  2. 6 0
      packages/ckeditor5-utils/tests/collection/collection.js

+ 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();