[API] Update view API

This commit is contained in:
Victor Woeltjen 2016-06-17 11:16:08 -07:00
parent 2240a87ddc
commit 96316de6e4
3 changed files with 37 additions and 33 deletions

View File

@ -21,9 +21,7 @@ define(['angular'], function (angular) {
}
var view = factories[key](mctObject);
var elements = view.elements();
element.empty();
element.append(elements);
view.show(element[0]);
}
function setKey(k) {

View File

@ -1,21 +1,24 @@
define(['EventEmitter'], function (EventEmitter) {
define(function () {
function View() {
EventEmitter.call(this);
}
View.prototype = Object.create(EventEmitter.prototype);
/**
* Show this view in the specified container. If this view is already
* showing elsewhere, it will be removed from that location.
*
* @param {HTMLElement} container the element to populate
*/
View.prototype.show = function (container) {
};
['elements', 'model'].forEach(function (method) {
View.prototype[method] = function (value) {
this.viewState =
this.viewState || { elements: [], model: undefined };
if (arguments.length > 0) {
this.viewState[method] = value;
this.emit(method, value);
}
return this.viewState[method];
}
});
/**
* Release any resources associated with this view.
*
* Subclasses should override this method to release any resources
* they obtained during a `show` call.
*/
View.prototype.destroy = function () {
};
return View;
});

View File

@ -22,23 +22,26 @@ define([
});
function TodoView(domainObject) {
mct.View.apply(this);
this.domainObject = domainObject;
this.filterValue = "all";
this.elements($(todoTemplate));
var $els = $(this.elements());
this.$buttons = {
all: $els.find('.example-todo-button-all'),
incomplete: $els.find('.example-todo-button-incomplete'),
complete: $els.find('.example-todo-button-complete')
};
this.initialize();
this.on('model', this.render.bind(this));
this.model(domainObject);
}
TodoView.prototype = Object.create(mct.View.prototype);
TodoView.prototype.show = function (container) {
this.$els = $(todoTemplate);
this.$buttons = {
all: this.$els.find('.example-todo-button-all'),
incomplete: this.$els.find('.example-todo-button-incomplete'),
complete: this.$els.find('.example-todo-button-complete')
};
$(container).empty().append(this.$els);
this.initialize();
this.render();
};
TodoView.prototype.destroy = function () {
};
TodoView.prototype.setFilter = function (value) {
this.filterValue = value;
@ -52,8 +55,8 @@ define([
};
TodoView.prototype.render = function () {
var $els = $(this.elements());
var domainObject = this.model();
var $els = this.$els;
var domainObject = this.domainObject;
var tasks = domainObject.getModel().tasks;
var $message = $els.find('.example-message');
var $list = $els.find('.example-todo-task-list');