Skip to content
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

Model/collection type checks should be configurable #116

Open
markerikson opened this issue Apr 15, 2015 · 0 comments
Open

Model/collection type checks should be configurable #116

markerikson opened this issue Apr 15, 2015 · 0 comments

Comments

@markerikson
Copy link

I previously reported issue #43, where several places in the codebase had hardcoded references to Backbone.Model. That issue was fixed (thanks), but I've just run into a similar issue.

Epoxy currently uses two internal functions, isModel() and isCollection(), to determine how to handle binding source setup (per

if (isModel(target)) {
). However, both those functions still have hardcoded references to Backbone.Model and Backbone.Collection.

I've started to use parts of the Ampersand library in my current codebase, including Ampersand-State (a forked and upgraded version of Backbone.Model). Amp.State still supports the same get()/set()/toJSON() API as Backbone.Model, so the core Epoxy binding logic should still work correctly. However, as currently written, the isModel() and isCollection() functions both fail when attempting to add an Amp.State instance to the binding context, as it is not a Backbone.Model.

I was able to get Epoxy and Ampersand-State to cooperate by hacking up my local copy of Epoxy to look like this:

    var isModel = function(obj) {
        var isBackboneModel = (obj instanceof Backbone.Model);
        var isAmpersandModel = (_.result(obj, "getType") == "model");
        return  isBackboneModel || isAmpersandModel;
    };

I really don't like using locally-modified copies of dependencies, though, so it would be nice if there was a way to override the built-in logic.

A comment on the previous issue links to a fork commit that exposes several inheritance-related pieces on the public Epoxy object. That commit appears to predate the official commit for #43, but the approach looks reasonable.

So, would it be possible to expose isModel() and isCollection() publicly so that they could be overwritten?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant