From f06fbcd358f15b3f98a3d3160be7b1136e8b1e7e Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Wed, 19 Apr 2017 12:11:49 +0200 Subject: [PATCH] Code refactoring: simplified Promise.all calls in View and ViewCollection classes. --- src/view.js | 10 ++-------- src/viewcollection.js | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/view.js b/src/view.js index ed16a694..59ec809d 100644 --- a/src/view.js +++ b/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(); diff --git a/src/viewcollection.js b/src/viewcollection.js index ec430b7f..5d05ede9 100644 --- a/src/viewcollection.js +++ b/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() ) ); } ); }