-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: this.adapter(...)[action] is not a function sightglass.js:159:8 #510
Comments
I am not sure if it matters but here is my configuration define(
[
'rivets'
],
function (Rivets) {
Rivets.configure({
// Attribute prefix in templates
prefix: 'rv',
// Preload templates with initial data on bind
preloadData: true,
// Root sightglass interface for keypaths
rootInterface: '.',
// Template delimiters for text bindings
//templateDelimiters: ['{', '}'],
templateDelimiters: ['{*{', '}*}'],
// Augment the event handler of the on-* binder
handler: function (target, event, binding) {
this.call(target, event, binding.view.models)
}
});
}
); |
I am not sure about binding.view.models, or what that's doing |
I think I figured out the problem here's a picture to help you help me, the image represents the adapter hash obj / associated array. looks like the there was breaking changes - I need to implement observe and unobserve instead of subscribe and unsubscribe, etc? is that right? as you can see from the image, my adapter[:] implements publish, read, subscribe,unsubscribe.... |
Seems to work now, I changed my adapter from this define(
[
'rivets',
'backbone'
],
function (Rivets, Backbone) {
// Rivets.js Backbone adapter
Rivets.adapters[':'] = {
// set the listeners to update the corresponding DOM element
subscribe: function (obj, keypath, callback) {
if (obj instanceof Backbone.Collection) {
obj.on('add remove reset', callback);
}
else if (obj instanceof Backbone.Model) {
obj.on('change:' + keypath, callback);
}
else {
throw new Error('Rivets error: not backbone model or collection');
}
},
// this will be triggered to unbind the Rivets.js events
unsubscribe: function (obj, keypath, callback) {
if (obj instanceof Backbone.Collection) {
obj.off('add remove reset', callback);
}
else if (obj instanceof Backbone.Model) {
obj.off('change:' + keypath, callback);
}
else {
throw new Error('Rivets error: not backbone model or collection');
}
},
// define how Rivets.js should read the property from our objects
read: function (obj, keypath) {
// if we use a collection we will loop through its models otherwise we just get the model properties
//TODO: @rhodee As of 0.3.2 there is a data-each-[item] binding to iterate over items in an array.
if( obj instanceof Backbone.Collection){
return obj.models
}
else if(obj instanceof Backbone.Model){
return obj.get(keypath);
}
else{
throw new Error('Rivets error: not backbone model or collection');
}
},
// It gets triggered whenever we want update a model using Rivets.js
publish: function (obj, keypath, value) {
obj.set(keypath, value);
}
};
}); to this define(
[
'rivets',
'backbone'
],
function (Rivets, Backbone) {
// Rivets.js Backbone adapter
Rivets.adapters[':'] = {
// set the listeners to update the corresponding DOM element
observe: function (obj, keypath, callback) {
if (obj instanceof Backbone.Collection) {
obj.on('add remove reset', callback);
}
else if (obj instanceof Backbone.Model) {
obj.on('change:' + keypath, callback);
}
else {
throw new Error('Rivets error: not backbone model or collection');
}
},
// this will be triggered to unbind the Rivets.js events
unobserve: function (obj, keypath, callback) {
if (obj instanceof Backbone.Collection) {
obj.off('add remove reset', callback);
}
else if (obj instanceof Backbone.Model) {
obj.off('change:' + keypath, callback);
}
else {
throw new Error('Rivets error: not backbone model or collection');
}
},
// define how Rivets.js should read the property from our objects
get: function (obj, keypath) {
// if we use a collection we will loop through its models otherwise we just get the model properties
//TODO: @rhodee As of 0.3.2 there is a data-each-[item] binding to iterate over items in an array.
if( obj instanceof Backbone.Collection){
return obj.models
}
else if(obj instanceof Backbone.Model){
return obj.get(keypath);
}
else{
throw new Error('Rivets error: not backbone model or collection');
}
},
// It gets triggered whenever we want update a model using Rivets.js
set: function (obj, keypath, value) {
obj.set(keypath, value);
}
};
}); FML can you prevent someone else from making the same mistake (following an old tutorial) that I made? perhaps you just missing one patch/ALIAS ? |
If you read the most current docs on the website, they illustrate these issues. The adapter syntax changed in the latest major semvar. I agree, A nice example of using rivets with backbone should be provided. You will also need to listen for the backbone Keep in mind, default backbone does not support nested properties. You cannot do something like, Here is an example of implementing infinate nesting with backbone models and collections. We use this with rivets all the time. Things like, Let me know if this helps. As with most things backbone, getting things to work with it is not totally easy, but once you get it working how you want. It feels like you have a Lamborghini and there is no magic. |
yeah, thanks, on the Rivets Guide page there is this as an example of two-way binding rivets.binders.toggle = {
bind: function(el) {
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)
}
$(el).on('click', this.callback)
},
unbind: function(el) {
$(el).off('click', this.callback)
},
routine: function(el, value) {
$(el)[value ? 'addClass' : 'removeClass']('enabled')
}
} it clearly is using the adapter.publish adapter.read functions, which are 'deprecated' is this all being maintained? I know it's a lot of work |
Right now the main man Mike is doing a rewrite. There are a few of us that are not official maintainers, but lurk super hard. Otherwise there are some random people here and there. As far as the word maintain... I am not sure there is actually anything "wrong" with it. There are many open issues but most are a muut point based on the authors implementation, or someones desire to se a binder make it into rivets core. There are many "nice to have" features. But the way rivets is made, you are supposed to implement custom binders, formatters and components to solve your problems. There is this thread: #500 Please close the issue if your problem is solved. |
word I appreciate it |
Could you please close your ticket if your question is answered? |
for sure |
I was following the directions that our supreme leader placed on JSFiddle prompted by a question on StackOverlow:
http://jsfiddle.net/eH4zG/252/
my code looks similar
but I get this
TypeError: this.adapter(...)[action] is not a function sightglass.js:159:8
my adapter is using the colon : like the example, but my only guess is that the adapter is not being picked up in my program? But it is being registered, I can verify that, so I can't explain this behavior.
The text was updated successfully, but these errors were encountered: