[API] Implement View

This commit is contained in:
Victor Woeltjen 2016-05-27 16:08:43 -07:00
parent 55b531bdeb
commit a07e2fb8e5

View File

@ -1,7 +1,24 @@
define(['EventEmitter'], function (EventEmitter) {
function View() {
function View(definition) {
var self = this;
var state = definition.state ? definition.state() : {};
function render() {
if (definition.render) {
definition.render(self.elements(), self.model(), state);
}
}
EventEmitter.call(this);
this.state = { elements: [], model: undefined };
if (definition.elements) {
this.elements(definition.elements());
}
if (definition.initialize) {
definition.initialize(this.elements(), render);
}
this.on('model', render);
}
View.prototype = Object.create(EventEmitter.prototype);