scope: { ... },
events: {
inserted: function () {
// ..init
this.scope.attr('computed', compute(initial, {
// get, set, on, off // bind to some plugin value
}));
},
removed: function () {
// do i have to tear down the computed? even if its on the scope thus within range of canjs?
}
}
sth like
scope: function (tagAttrs, parentScope, elem) {
return {
define: {
computed: {
// `value/Value, type/Type, get, set, serialize` etc.
// access to `elem` yes, but without the `on` and `off` options this is a dead end, what now?
}
}
}
}
using the define plugin there is no on
and off
options, how to circumvent that?
var input = document.getElementById("age")
var value = can.compute("",{
get: function(){
return input.value;
},
set: function(newVal){
input.value = newVal;
},
on: function(updated){
input.addEventListener("change", updated, false);
},
off: function(updated){
input.removeEventListener("change", updated, false);
}
})
inserted
and removed
with the listeners setting and changing scope/viewModel properties but that scatters the whole logic to maintain one attribute over three places sope
/viewModel
events.inserted
and events.removed
which is way inferior to the above almost self-contained approach. sry, i have to leave, i'll be back later this day
'{scope.promise} change’: function () { … }
. change
events in CanJS are not the same as in other libraries.
change
means that some property on an entire object has changed.
var map = new can.Map({ foo: ‘bar’, boo: ‘baz’ });
map.bind(‘change’, function () { console.log(‘!!!’) });
map.attr(‘foo’, ‘baz’); //-> !!!
map.attr(‘boo’, ‘bar’); //-> !!!
var map = new can.Map({ foo: ‘bar’, boo: ‘baz’ });
map.bind(‘boo’, function () { console.log(‘!!!’) });
map.attr(‘foo’, ‘baz’); //->
map.attr(‘boo’, ‘bar’); //-> !!!
‘{scope} promise’: function () { … }
change
events have a lot of overhead. For performance reasons they should be avoided when possible.
promise
is dependent on state
, it causes a loop.
it seems the promise's call to attr('state', state)
sets up a dependency if i'm not mistaken, anyway.
if you could fix the jsbin to work without binding a noop handler to work correctly i.e.
state
when promise
changes and when resolved/rejectedpromise
if idKey
changesmodel
when promise
resolvesthat would grant me a good night sleep!
idKey
setter kind of defeats the purpose of observables, after all, idKey
shouldn't have to know what depends on it at all. i'll call it a day. again thanks for your time and efforts! hope to see you around here soon.
{{#each}}
helper: http://jsbin.com/warebexisa/edit?html,js,output