return this.promise().state()
won't setup the dependency either.
Component.extend({
...
scope: MapCtr,
events: {
'{scope} promise': noop,
...
}
...
});
yes it did, however, state
does not revaluate itself when promise
does. i was expecting any call to .attr
would bind
the computed being created to that attribute, but it doesn't. which is why i tried sth. like
Component.extend({
...
scope: {
promise: '...',
state: compute(function (newState) {
if (arguments.length) return newState;
var self = this;
self.bind('promise', function (evt, newPromise) {
newPromise.always(function () {
self.attr('state', this.state());
})
})
})
}
...
});
but that doesn't work either.
can/list/promise
does
attr
doesn't duffice
bind
i implemented through the component's events
object which btw i don't understand the naming of - why not just control
?
viewModel
/scope
(are these the same?) computed properties access to dom elements? here is the draft:Component.extend({
scope: {
question: computed(function () {
return howToAccessThisComponentsElement; // ?
})
}
})
Component.extend({
viewModel: {
internalProp: compute({
get: function () {
// missing element access here
},
set: '', // set
on: '', // bind to the plugin's custom events
off: '', // unbind from the plugin's custom events
})
},
events: {
inserted: '', // init 3rd party plugin on element
removed: '' // teardown 3rd party plugin from element
}
});
removed
event occur after the element has been removed or just before that?
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.