Fixes #400 - Introduce state as a local variable

This commit is contained in:
Patrick Steele-Idem 2016-11-11 22:53:33 -07:00
parent 520706a945
commit 6eb006d89c
5 changed files with 18 additions and 2 deletions

View File

@ -0,0 +1,7 @@
module.exports = {
onInput: function() {
this.state = {
name: 'Frank'
};
}
};

View File

@ -0,0 +1,3 @@
<div w-bind>
Hello ${state.name}!
</div>

View File

@ -0,0 +1,6 @@
var expect = require('chai').expect;
module.exports = function(helpers) {
var widget = helpers.mount(require('./index'), {});
expect(widget.el.innerHTML).to.contain('Frank');
};

View File

@ -130,7 +130,7 @@
"@id": "string",
"@hasDomEvents": "number",
"@body": "string",
"var": "widget",
"vars": ["widget", "state"],
"import-var": {
"_cfg": "data.widgetConfig",
"_state": "data.widgetState",

View File

@ -210,7 +210,7 @@ module.exports = function widgetTag(input, out) {
// Only render the widget if it needs to be rerendered
if (shouldRenderBody) {
input.renderBody(out, widgetDef);
input.renderBody(out, widgetDef, state);
markoWidgets.writeDomEventsEl(widgetDef, out);
}