rivets
rivets copied to clipboard
Guide : Binders doc incorrect (v0.8.1)
What might be the correct way to implement the binder as shown on the Guide page? What I'm noticing is that the this.config
is not available when bind
is called. Neither is this.key.interface
. I'm guessing the API changed and the guide hasn't been updated to reflect the change.
rivets.binders.toggle = {
bind: function(el) {
// both this.config and this.key.interface don't appear bound when bind is called in v0.8.1
// as per the guide http://rivetsjs.com/docs/guide/
adapter = this.config.adapters[this.key.interface]
model = this.model
keypath = this.keypath
this.callback = function() {
value = adapter.read(model, keypath)
adapter.publish(model, keypath, !value)
}
If anyone knows the work around could you share? Thanks.
I had the same problem and ended up using this:
var adapter = rivets.adapters[rivets.rootInterface];
It's weird that the guide wasn't updated - makes it pretty hard to get started
On Fri, Apr 24, 2015 at 5:34 AM, Lucas Caballero [email protected] wrote:
What might be the correct way to implement the binder as shown on the Guide page? What I'm noticing is that the this.config is not available when bind is called. Neither is this.key.interface. I'm guessing the API changed and the guide hasn't been updated to reflect the change.
rivets.binders.toggle = { bind: function(el) { // both this.config and this.key.interface don't appear bound when bind is called in v0.8.1 // as per the guide http://rivetsjs.com/docs/guide/ adapter = this.config.adapters[this.key.interface] model = this.model keypath = this.keypath
this.callback = function() { value = adapter.read(model, keypath) adapter.publish(model, keypath, !value) }
If anyone knows the work around could you share? Thanks.
— Reply to this email directly or view it on GitHub https://github.com/mikeric/rivets/issues/476.
ben liebert blackball software ltd, www.blackballsoftware.com
Yes please, this doc should be updated. I've been trying to get the model corresponding to my keypath for hours now. My model is
data = {
stuff: {
thing: []
}
};
With a keypath of data.stuff.thing, how am I supposed to get my array within a binder definition?
Adapters don't have a "read" method so it should be replaced. adapter.publish can be changed into that.publish (where "that" is the "this" from the bind method).
So we could do something like that maybe?
rivets.binders.toggle = {
bind: function(el) {
var that = this;
adapter = rivets.adapters[rivets.rootInterface];
model = this.model
keypath = this.keypath
this.callback = function() {
value = ??? // adapter.get(model, keypath) doesn't seem to work fine
that.publish(model, keypath, !value)
}
Thanks.
I got it working like this:
adapter = rivets.adapters[this.observer.key.i]
model = this.model
key = this.observer.key.path
this.callback = function () {
value = adapter.get(model,key)
adapter.set(model, key, ! value)
}
Is that the current way to go?
var self = this; this.callback = function () { self.observer.setValue(some_value); };