ractivejs - When to use the promise returned by ractive.set? -
the ractive.set method returns promise. when performing simple set operation (single value or map) , referencing new value via ractive.get, recommended use promise? or unnecessary?
i've been avoiding promise , found don't need it, maybe i've been lucky far. here's example of mean:
ractive.set("foo", "bar"); console.log(ractive.get("foo")); // outputs correct value "bar"
i'm worried set operation asynchronous , become evident on slower machines or if start using more advanced features of ractive.
according ractive docs:
[ractive.set] returns promise will called after set operation , transitions complete.
based on that, wonder if promise meant post-transition work.
based on that, wonder if promise meant post-transition work.
exactly. value update (and resulting dom changes per template) happen synchronously, promise meant asynchronous response end of transitions.
this why set
operation has hash map option input parameters multiple sets batched in 1 go:
ractive.set({ foo: 'foo', bar: 'bar' }).then( () => { // happens asynchronously ***after*** code execution has // continued below on next event cycle or after transitions complete }); // data , dom have been updated code continues synchronously here: console.log( ractive.get() );
Comments
Post a Comment