Merge pull request #7093 from jasongrout/model-views

Make the model.views dict a dict of promises for views
This commit is contained in:
Jonathan Frederic 2014-12-05 08:31:06 -08:00
commit e519371402
2 changed files with 7 additions and 7 deletions

View File

@ -112,6 +112,7 @@ define([
return Promise.resolve(view.render()).then(function() {return view;});
}).catch(utils.reject("Couldn't create a view for model id '" + String(model.id) + "'", true));
});
model.views[utils.uuid()] = model.state_change;
return model.state_change;
};

View File

@ -65,11 +65,12 @@ define(["widgets/js/manager",
delete this.comm.model; // Delete ref so GC will collect widget model.
delete this.comm;
delete this.model_id; // Delete id from model so widget manager cleans up.
for (var id in this.views) {
if (this.views.hasOwnProperty(id)) {
this.views[id].remove();
}
}
_.each(this.views, function(v, id, views) {
v.then(function(view) {
view.remove();
delete views[id];
});
});
},
_handle_comm_msg: function (msg) {
@ -318,8 +319,6 @@ define(["widgets/js/manager",
*/
this.model.on('change',this.update,this);
this.options = parameters.options;
this.id = this.id || utils.uuid();
this.model.views[this.id] = this;
this.on('displayed', function() {
this.is_displayed = true;
}, this);