Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Code refactoring: simplified Promise.all calls in View and ViewCollec…
Browse files Browse the repository at this point in the history
…tion classes.
  • Loading branch information
oleq committed Apr 19, 2017
1 parent 4cd9205 commit f06fbcd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
10 changes: 2 additions & 8 deletions src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) );
}

/**
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/viewcollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
} );
}

Expand Down

0 comments on commit f06fbcd

Please sign in to comment.