component / reactive

Tiny reactive template engine
382 stars 48 forks source link

model change doesn't update the view with data-text #162

Open timaschew opened 9 years ago

timaschew commented 9 years ago

So this issue is not about the initial rendering, it' about changing the model after the initial rendering.

For arrays and each it works fine:

var template = '<ul><li each="list">{this}</li></ul>';
var model = {
    list: ['a', 'b', 'c']
};
var view = reactive(template, model);
window.model = model;

If I load the page and then change it via the browser console with commands like window.model.list.pop() or window.model.list.push('d') the view is updated automatically

If I do the same with just a simple string and data-text instead of an array it doesn't work anymore:

var template = '<h1 data-text="title"></h1>';
var model = {
    title: 'foobar'
};
var view = reactive(template, model);
window.model = model;

any changes via window.model.title = 'test' had no effects, even if I use component model

chemzqm commented 8 years ago

Model should emit events for change and reactive should subscribe for the events, otherwise, the view never changes. Reactive did those for original array in each.js, but for other models, they should publish the change events, and an appropriate adapter should be provide to reactive.