gmac / backbone.epoxy

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

Can I use this with Backbone-relational #108

Closed itsmepetrov closed 9 years ago

itsmepetrov commented 9 years ago

How can I use Epoxy.Model with Backbone-relational Model http://backbonerelational.org ? They both override "set" and "get" functions.

gmac commented 9 years ago

I know very little about Backbone Relational. You'll have to do some testing if you feel that you absolutely must have a single component extend two disparate third-party libraries.

kevincolten commented 9 years ago

After much frustration, I was able to successfully mixin Backbone.Relational and Epoxy.Model using Backbone.Cocktail like this:

    Backbone.Epoxy.Model.prototype._super = Backbone.RelationalModel;
    var baseModel = Backbone.RelationalModel.extend({});
    var initMixin = {
        initialize: function() {
            this.initComputeds();
        }
    };
    Cocktail.mixin(baseModel, Backbone.Epoxy.Model.mixin(), initMixin);
    var relationalEpoxyModel = new baseModel();

Disclaimer: this will affect all Epoxy.Model instances since you are adding it to the prototype.

valaxy commented 9 years ago

~~I think this is not a correct solution, mixin Backbone.Relational & Backbone.Epoxy without change source code is almost impossible. The most serious problem is both of them(Model for example) treat Backbone.Model as their super Class, which is not always true.~~ Forgive my blinding, I diden't see: Backbone.Epoxy.Model.prototype._super = Backbone.RelationalModel It's really a good polyfill