[API] Synchronize view to model

This commit is contained in:
Victor Woeltjen 2016-06-17 14:21:37 -07:00
parent 4a50f325cb
commit 370b515c23
2 changed files with 12 additions and 0 deletions

View File

@ -106,6 +106,10 @@ define([
var persistence = domainObject.getCapability('persistence'); var persistence = domainObject.getCapability('persistence');
return persistence.persist(); return persistence.persist();
}); });
},
observe: function (domainObject, callback) {
var mutation = domainObject.getCapability('mutation');
return mutation.listen(callback);
} }
}; };

View File

@ -29,6 +29,8 @@ define([
} }
TodoView.prototype.show = function (container) { TodoView.prototype.show = function (container) {
this.destroy();
this.$els = $(todoTemplate); this.$els = $(todoTemplate);
this.$buttons = { this.$buttons = {
all: this.$els.find('.example-todo-button-all'), all: this.$els.find('.example-todo-button-all'),
@ -40,9 +42,15 @@ define([
this.initialize(); this.initialize();
this.render(); this.render();
mct.verbs.observe(this.domainObject, this.render.bind(this));
}; };
TodoView.prototype.destroy = function () { TodoView.prototype.destroy = function () {
if (this.unlisten) {
this.unlisten();
this.unlisten = undefined;
}
}; };
TodoView.prototype.setFilter = function (value) { TodoView.prototype.setFilter = function (value) {