Show More
@@ -661,10 +661,9 b' define(["widgets/js/manager",' | |||
|
661 | 661 | |
|
662 | 662 | _.extend(ViewList.prototype, { |
|
663 | 663 | initialize: function(create_view, remove_view, context) { |
|
664 | this.state_change = Promise.resolve(); | |
|
665 | 664 | this._handler_context = context || this; |
|
666 | 665 | this._models = []; |
|
667 | this.views = []; | |
|
666 | this.views = []; // list of promises for views | |
|
668 | 667 | this._create_view = create_view; |
|
669 | 668 | this._remove_view = remove_view || function(view) {view.remove();}; |
|
670 | 669 | }, |
@@ -673,42 +672,36 b' define(["widgets/js/manager",' | |||
|
673 | 672 | /** |
|
674 | 673 | * the create_view, remove_view, and context arguments override the defaults |
|
675 | 674 | * specified when the list is created. |
|
676 | * returns a promise that resolves after this update is done | |
|
675 | * after this function, the .views attribute is a list of promises for views | |
|
676 | * if you want to perform some action on the list of views, do something like | |
|
677 | * `Promise.all(myviewlist.views).then(function(views) {...});` | |
|
677 | 678 | */ |
|
678 | 679 | var remove = remove_view || this._remove_view; |
|
679 | 680 | var create = create_view || this._create_view; |
|
680 | if (create === undefined || remove === undefined){ | |
|
681 | console.error("Must define a create a remove function"); | |
|
682 | } | |
|
683 | 681 | var context = context || this._handler_context; |
|
684 |
var |
|
|
685 | var that = this; | |
|
686 | this.state_change = this.state_change.then(function() { | |
|
687 | var i; | |
|
682 | var i = 0; | |
|
688 | 683 |
|
|
689 |
|
|
|
690 |
|
|
|
684 | for (; i < new_models.length; i++) { | |
|
685 | if (i >= this._models.length || new_models[i] !== this._models[i]) { | |
|
691 | 686 |
|
|
692 | 687 |
|
|
693 | 688 |
|
|
689 | ||
|
694 | 690 |
|
|
695 | 691 |
|
|
696 | for (var j = first_removed; j < that._models.length; j++) { | |
|
697 | remove.call(context, that.views[j]); | |
|
692 | var removed = this.views.splice(first_removed, this.views.length-first_removed); | |
|
693 | for (var j = 0; j < removed.length; j++) { | |
|
694 | removed[j].then(function(view) { | |
|
695 | remove.call(context, view) | |
|
696 | }); | |
|
698 | 697 |
|
|
699 | 698 | |
|
700 | 699 |
|
|
701 | 700 |
|
|
702 |
|
|
|
701 | this.views.push(Promise.resolve(create.call(context, new_models[i]))); | |
|
703 | 702 |
|
|
704 | 703 |
|
|
705 |
|
|
|
706 | return Promise.all(added_views).then(function(added) { | |
|
707 | Array.prototype.splice.apply(that.views, [first_removed, that.views.length].concat(added)); | |
|
708 | return that.views; | |
|
709 | }); | |
|
710 | }); | |
|
711 | return this.state_change; | |
|
704 | this._models = new_models.slice(); | |
|
712 | 705 | }, |
|
713 | 706 | |
|
714 | 707 | remove: function() { |
@@ -718,14 +711,13 b' define(["widgets/js/manager",' | |||
|
718 | 711 | * returns a promise that resolves after this removal is done |
|
719 | 712 | */ |
|
720 | 713 | var that = this; |
|
721 | this.state_change = this.state_change.then(function() { | |
|
714 | return Promise.all(this.views).then(function(views) { | |
|
722 | 715 | for (var i = 0; i < that.views.length; i++) { |
|
723 |
that._remove_view.call(that._handler_context, |
|
|
716 | that._remove_view.call(that._handler_context, views[i]); | |
|
724 | 717 | } |
|
725 | that._models = []; | |
|
726 | 718 | that.views = []; |
|
719 | that._models = []; | |
|
727 | 720 | }); |
|
728 | return this.state_change; | |
|
729 | 721 | }, |
|
730 | 722 | }); |
|
731 | 723 |
General Comments 0
You need to be logged in to leave comments.
Login now