Sfoglia il codice sorgente

Fixed: A View#id Number breaks parent ViewCollection.

Aleksander Nowodzinski 9 anni fa
parent
commit
52d224da47

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

@@ -70,6 +70,10 @@ export default class ViewCollection extends Collection {
 		 * @member {HTMLElement} ui.ViewCollection#_boundItemsToViewsMap
 		 */
 		this._boundItemsToViewsMap = new Map();
+
+		// An #id Number attribute should be legal and not break the `ViewCollection` instance.
+		// https://github.com/ckeditor/ckeditor5-ui/issues/93
+		this._idProperty = 'viewUid';
 	}
 
 	/**

+ 13 - 1
packages/ckeditor5-ui/tests/viewcollection.js

@@ -27,6 +27,7 @@ describe( 'ViewCollection', () => {
 			expect( collection.ready ).to.be.false;
 			expect( collection._parentElement ).to.be.null;
 			expect( collection._boundItemsToViewsMap ).to.be.instanceOf( Map );
+			expect( collection._idProperty ).to.equal( 'viewUid' );
 		} );
 
 		it( 'accepts locale and defines the locale property', () => {
@@ -139,7 +140,7 @@ describe( 'ViewCollection', () => {
 		} );
 	} );
 
-	describe( 'add', () => {
+	describe( 'add()', () => {
 		it( 'returns a promise', () => {
 			expect( collection.add( {} ) ).to.be.instanceof( Promise );
 		} );
@@ -169,6 +170,17 @@ describe( 'ViewCollection', () => {
 				} );
 			} );
 		} );
+
+		it( 'works for a view with a Number view#id attribute', () => {
+			const view = new View();
+
+			view.set( 'id', 1 );
+
+			return collection.add( view ).then( () => {
+				expect( view.id ).to.equal( 1 );
+				expect( view.viewUid ).to.be.a( 'string' );
+			} );
+		} );
 	} );
 
 	describe( 'setParent', () => {