bminer / node-blade

Blade - HTML Template Compiler, inspired by Jade & Haml
Other
320 stars 28 forks source link

Live updating views #171

Closed sweiz closed 11 years ago

sweiz commented 11 years ago

I'm attempting to update the views from outside the template, but the view will not reflect the changes to the model unless I re-render it; var thisModel = new blade.model({"title": "Hello World"}); $('wrap').render('wrapView', thisModel, function() { thisModel.set("title", "Hello Earth") // Doesn't update view unless I run render again. }):

Have tried;

model.add("clicks", 0); var x = model.observable; console.log(x.clicks); //calls model.get("clicks") and prints 0 x.clicks = 20; //calls model.set("clicks", 20)

and

var users = [ ...data goes here... ]; var m = new blade.Model({"users": users}); //... Then later... users[2].firstName = "Ben"; //This does not trigger Model.set or invalidate any contexts //Nor does this... m.observable.users[2].firstName = "Ben"; //This only calls Model.get //To actually invalidate Contexts, you have to invoke Model.set... but wait... m.set("users", users); //Oh, crap! Even this didn't work because the value was unchanged! m.invalidate("users"); //Finally, it works! (invalidate() function was added in Blade 2.6.0)

from the wiki but neither seem to work unless I re-render the view. Am I missing something? Any help would be greatly appreciated.

sweiz commented 11 years ago

It now works, and I don't know what I've done to make it work; quite likely I'm retarded. Please close this issue if possible.

Full props for blade, loving it!