Răsfoiți Sursa

Code refactoring: simplified Promise.all calls in View and ViewCollection classes.

Aleksander Nowodzinski 8 ani în urmă
părinte
comite
be21c703d1

+ 2 - 8
packages/ckeditor5-ui/src/view.js

@@ -276,13 +276,7 @@ export default class View {
 			children = [ children ];
 		}
 
-		const promises = [];
-
-		for ( let child of children ) {
-			promises.push( this._unboundChildren.add( child ) );
-		}
-
-		return Promise.all( promises );
+		return Promise.all( children.map( c => this._unboundChildren.add( c ) ) );
 	}
 
 	/**
@@ -319,7 +313,7 @@ export default class View {
 	destroy() {
 		this.stopListening();
 
-		return Promise.all( Array.from( this._viewCollections, c => c.destroy() ) )
+		return Promise.all( this._viewCollections.map( c => c.destroy() ) )
 			.then( () => {
 				this._unboundChildren.clear();
 				this._viewCollections.clear();

+ 1 - 1
packages/ckeditor5-ui/src/viewcollection.js

@@ -114,7 +114,7 @@ export default class ViewCollection extends Collection {
 		return Promise.all( this._addPromises )
 			// Then begin the process of destroying the children.
 			.then( () => {
-				return Promise.all( Array.from( this, view => view.destroy() ) );
+				return Promise.all( this.map( v => v.destroy() ) );
 			} );
 	}