gmac / backbone.epoxy

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

mixin bindings #111

Closed davis closed 8 years ago

davis commented 9 years ago

Hello, I am using Marionette's views and would like to have binding on them (but JavaScript doesn't support multiple inheritance). Is there a way to "mix-in" the Epoxy features?

patrick-radius commented 9 years ago

Yes, See docs http://epoxyjs.org/documentation.html#model-mixin and http://epoxyjs.org/documentation.html#view-mixin b ut beware of the target being a prototype, It was confusing to me sometimes

davis commented 9 years ago

thanks!

markerikson commented 9 years ago

Yeah, in my current project, I've created an EpoxyItemView base class using the following code:

    function createMarionetteEpoxyMergedView(marionetteClass) {
        var mergedClass = marionetteClass.extend({
            onItemRendered : function() {
                this.applyBindings();
            }
        });
        Backbone.Epoxy.View.mixin(mergedClass.prototype);
        return mergedClass;
    }

    var EpoxyItemView = createMarionetteEpoxyMergedView(Backbone.Marionette.ItemView);

Works great.

markerikson commented 9 years ago

For that matter, issue #94 shows some other ways to mix Marionette and Epoxy.