You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fortunately, because of the (in my opinion, buggy) way that JavaScript constructors work, you can already do collections with polymorphic models. Like so:
var Library = Backbone.Collection.extend({
model: function(attrs, options) {
if (condition) {
return new PublicDocument(attrs, options);
} else {
return new PrivateDocument(attrs, options);
}
}
});
Howdy!
Right now backbone seems to only support collections of one type, we're working on a stream with many polymorphic types that all quack the same.
It'd be nice to implement this via inheritance(extend), rather than our current technique of creating proxies/mixins in the base class.
backbone collection seems to have a hardcoded new this.model in it,
I was thinking about doing something like:
this.model = this.model || this.modelClass()
is this a change you would like to have implemented, or are you opposed to it for an ideological reason?
If you want it, I'll implemented, as it will help me on a couple projects I'm working on.
The text was updated successfully, but these errors were encountered: