gmac / backbone.epoxy

Declarative data binding and computed models for Backbone
http://epoxyjs.org
MIT License
615 stars 89 forks source link

Access to view in bindingHandlers #48

Open rubenstolk opened 10 years ago

rubenstolk commented 10 years ago

I think it would be nice if the bindingHandlers are called with a 3rd argument which is the view, this will make it easier to access for example given options on the view.

gmac commented 10 years ago

Could you provide an implementation example to demonstrate what you're referring to, please?

rubenstolk commented 10 years ago

Currently bindingHandlers are kind of static functions without any context. If for example I want to calculate something based on information available in the view, this is currently not possible. That's why I think it would be a great option to be able to have access to the view...

kottenator commented 10 years ago

I have found one workaround:

this inside a custom binding handler in a reference to the model and inside the model there is a view link:

bindingHandlers: {
    myHandler: function($element, value) {
        var view = this.view;
        // ...
    }
}

However, this is not a good solution, because the model could be used in different views at the same time...

It would be good if Epoxy developers would add an additional argument to the handler function:

bindingHandlers: {
    /** @param {Backbone.View} view */
    myHandler: function($element, value, view) {
        // ...
    }
}