gmac / backbone.epoxy

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

Pass a collectionView's options to its itemView constructors. #119

Closed adamsea closed 8 years ago

adamsea commented 9 years ago

Hello,

Is there a way to pass options from a collectionView instance to individual itemView instances as they are created? Looking at the following:

https://github.com/gmac/backbone.epoxy/blob/master/backbone.epoxy.js#L693

I see only the model (each collection member) and the collectionView are passed as options. Should there be a specific options object created that could be used to pass along to itemViews? I'd be happy to create a PR if we can agree this functionality is beneficial and find a sane way to accomplish it.

Thanks! -Eric

adamsea commented 9 years ago

For a little bit of context, here's some code I used to work around this in the meantime:

this.listenTo(this.collectionView, 'options.set', function(options) {
    this.setViewOptions(options);
    this.applyBindings();
});

So I can set them after the itemViews are created, but this requires calling applyBindings multiple times and seems inefficient.

markerikson commented 9 years ago

For what it's worth, this is where Marionette works really well. Their CollectionView includes exactly this sort of setup behavior.

gmac commented 8 years ago

@adamsea thanks for the input. By all means, please PR!