mirror of
https://github.com/nasa/openmct.git
synced 2025-06-15 13:48:12 +00:00
[API] Implement View
This commit is contained in:
@ -1,7 +1,24 @@
|
|||||||
define(['EventEmitter'], function (EventEmitter) {
|
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);
|
EventEmitter.call(this);
|
||||||
this.state = { elements: [], model: undefined };
|
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);
|
View.prototype = Object.create(EventEmitter.prototype);
|
||||||
|
Reference in New Issue
Block a user