Comparing version 0.1.0 to 0.2.0
@@ -70,7 +70,7 @@ 'use strict'; | ||
value: function update() { | ||
var propsUpdate = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var stateUpdate = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var updateHash = '$fragment' in propsUpdate && propsUpdate.$fragment !== this.state.$fragment; | ||
var updateHash = '$fragment' in stateUpdate && stateUpdate.$fragment !== this.state.$fragment; | ||
Object.assign(this.state, propsUpdate); | ||
Object.assign(this.state, stateUpdate); | ||
if (this.loop) { | ||
@@ -77,0 +77,0 @@ this.loop.update(this.state); |
@@ -9,2 +9,4 @@ 'use strict'; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -14,2 +16,4 @@ | ||
function View(parent) { | ||
var _this = this; | ||
var initialState = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
@@ -21,2 +25,8 @@ | ||
this.initialState = initialState; | ||
this._template = this.TEMPLATE; | ||
this._views = this.VIEWS; | ||
this._viewRenderers = Object.keys(this._views).reduce(function (renderers, vname) { | ||
var view = _this._views[vname]; | ||
return Object.assign({}, renderers, _defineProperty({}, vname, view.render.bind(view))); | ||
}, {}); | ||
} | ||
@@ -27,5 +37,7 @@ | ||
value: function render(state) { | ||
return this.template(Object.assign({}, state, { | ||
return this._template(Object.assign({}, state, { | ||
handlers: this.templateHandlers, | ||
helpers: this.templateHelpers | ||
helpers: this.templateHelpers, | ||
state: state, | ||
views: this._viewRenderers | ||
})); | ||
@@ -36,14 +48,21 @@ } | ||
value: function setApp(app) { | ||
var _this2 = this; | ||
this.app = app; | ||
Object.assign(app.state, this.initialState); | ||
this.views && this.views.forEach(function (v) { | ||
return v.setApp(app); | ||
Object.keys(this._views).forEach(function (v) { | ||
return _this2._views[v].setApp(app); | ||
}); | ||
} | ||
}, { | ||
key: 'template', | ||
key: 'TEMPLATE', | ||
get: function get() { | ||
console.error('No template function provided'); | ||
throw 'TEMPLATE must be provided by subclass'; | ||
} | ||
}, { | ||
key: 'VIEWS', | ||
get: function get() { | ||
return {}; | ||
} | ||
}, { | ||
key: 'templateHandlers', | ||
@@ -50,0 +69,0 @@ get: function get() { |
@@ -36,6 +36,6 @@ import create from 'virtual-dom/create-element'; | ||
update(propsUpdate={}) { | ||
const updateHash = '$fragment' in propsUpdate && propsUpdate.$fragment !== this.state.$fragment; | ||
update(stateUpdate={}) { | ||
const updateHash = '$fragment' in stateUpdate && stateUpdate.$fragment !== this.state.$fragment; | ||
Object.assign(this.state, propsUpdate); | ||
Object.assign(this.state, stateUpdate); | ||
if (this.loop) { | ||
@@ -42,0 +42,0 @@ this.loop.update(this.state); |
@@ -5,8 +5,18 @@ export default class View { | ||
this.initialState = initialState; | ||
this._template = this.TEMPLATE; | ||
this._views = this.VIEWS; | ||
this._viewRenderers = Object.keys(this._views).reduce((renderers, vname) => { | ||
const view = this._views[vname]; | ||
return Object.assign({}, renderers, {[vname]: view.render.bind(view)}); | ||
}, {}); | ||
} | ||
get template() { | ||
console.error('No template function provided'); | ||
get TEMPLATE() { | ||
throw 'TEMPLATE must be provided by subclass'; | ||
} | ||
get VIEWS() { | ||
return {}; | ||
} | ||
get templateHandlers() { | ||
@@ -21,6 +31,8 @@ return {}; | ||
render(state) { | ||
return this.template( | ||
return this._template( | ||
Object.assign({}, state, { | ||
handlers: this.templateHandlers, | ||
helpers: this.templateHelpers | ||
helpers: this.templateHelpers, | ||
state, | ||
views: this._viewRenderers, | ||
}) | ||
@@ -33,4 +45,4 @@ ); | ||
Object.assign(app.state, this.initialState); | ||
this.views && this.views.forEach(v => v.setApp(app)); | ||
Object.keys(this._views).forEach(v => this._views[v].setApp(app)); | ||
} | ||
} |
{ | ||
"name": "panel", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "virtual-dom view management and routing", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
16231
381