clayallsopp / react.backbone

Plugin for React to make Backbone migration easier
MIT License
839 stars 60 forks source link

Use with Filtered Collection #32

Closed nnnnathann closed 9 years ago

nnnnathann commented 9 years ago

Hi,

I often use a filtered collection library for collections, and unfortunately they do not test as instances of Backbone.Collection, which makes them behave as models using this library (relevant code).

What do you think about adding in a way to specify the behavior, or possibly switching the ternary to test Backbone.Model?

Relevant code:

var behavior = modelOrCollection instanceof Backbone.Collection ? collectionBehavior : modelBehavior;

Thank you for sharing your efforts on this library.

markijbema commented 9 years ago

I wouldn't be in favor of switching it around. This would undoubtly result in similar problems for people using specialized model libraries. I'd be in favor of making this more configurable though. If you could make this more general without linking it to specific libraries I would be in favor.

Maybe something like a library-level config? Something like this:

React.BackboneMixin.ConsiderAsCollection = [Backbone.Collection, FilteredCollection]

or alternatively assign it a function which decides whether this is a model or a collection. Your opinion @clayallsopp ?

nnnnathann commented 9 years ago

I like that solution @markijbema

clayallsopp commented 9 years ago

:+1: I'd prefer allowing configuration, and I think a function is preferable over an array