-
Notifications
You must be signed in to change notification settings - Fork 9
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
allow custom types to be created and run #22
Conversation
Even though I like the flexibility idea of this, i'm not thrilled about extending view in order to support this. I wonder if we shouldn't do this entirely just by letting users pass a function instead of a string "type" Then this would be the only thing needed for adding custom binding types: var View = require('ampersand-view');
var myBindingFunc = require('my-binding-func');
View.extend({
bindings: {
'model.name': {
type: myBindingFunc,
hook: 'name'
}
}
}); |
@HenrikJoreteg I agree that adding to the view API isn't really necessary here since the example you showed is pretty simple and easy to grasp. It was already possible with this PR to pass in a function as the domBindings({
'model.key': {
type: function (el, value, previousValue) { /* ... */ },
selector: '.thing'
}
}); |
@@ -174,6 +174,13 @@ function getBindingFunc(binding) { | |||
}); | |||
} | |||
}; | |||
} else if (typeof type === 'function') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the minor feedback i mentioned is i'd rather we determine at the top while we're doing the "parsing" anyway whether or not this is a custom binding and if so applying it. Rather than doing that as the last check since we're comparing all the others against strings.
basically determininng if it's a function or string first.
…dded a test for error types
allow custom types to be created and run
Hi there, quick follow up to this. Any chance we could get the binding context passed through to the custom binding function too? I need to do something like the following:
I'm sure there's a different way to implement it, this just occurred to me as pretty elegant if it could be supported. Thanks! |
@elainemacurdy you may want to file a seperate issue for your question - it was made on a closed PR and that will reduce it's visibility |
Oh fair enough, sorry I missed that it was closed. I'll do that. |
The API for
ampersand-dom-bindings
would be:The idea is that
ampersand-view
could have abindingTypes
hash that would get passed toampersand-dom-bindings
so that they could be used like this:Closes #21