Getting ItemView render notifications to CollectionView owner #229

kevindente opened this Issue Aug 23, 2012 · 6 comments


None yet
4 participants

kevindente commented Aug 23, 2012

OK, this may be just me. But I'm running into a situation where it would be handy for a CollectionView's owner to be informed of when a new ItemView is rendered (specifically, I want to tweak something on the ItemView, but only for the first ItemView in the CollectionVIew). I'm not seeing a real easy way to be informed of this occurrence. One solution would be for the CollectionView to forward itemview render events (currently child view event forwarding isn't hooked up until after rendering). Or maybe there's another approach I'm missing.


boxxxie commented Aug 24, 2012

could the collection view render different types of item views? subclass your view?
composite view?

bline commented Aug 24, 2012

I had this same issue. My first thought was to move where the event forwarding is hooked up to before the call to render. Instead of changing Marionette I decided to use the event aggregator. In the main parent view's (composite) constructor I create the event aggregator:

this.vent = new Marionette.EventAggregator()
this.itemViewOptions = { vent: this.vent };

and in the children's constructor I have:

this.vent = options.vent;
this.on('item:rendered', function () {
    this.vent.trigger('session:rendered', this);
}, this);

I have many subviews (both composite and itemview) of the main view and this solution allows me to propagate all the events up through the chain without having to guess strange propagated names like "itemview:itemview:composite:rendered"


kevindente commented Aug 24, 2012

@bline - I came up with a slightly different solution - override onItemAdded on the CollectionView, and have it listen for and forward the itemrendered event.

However, both of our solutions have the same problem I think. Let's say someone catches the rendered event, and then manipulates the child view (calls a method on it, for example). If that manipulation causes an event to be triggered on the child view, that event won't be forwarded up through the collection, because that binding hasn't been set up yet.


derickbailey commented Dec 2, 2012

this is rather odd... i'm looking at the code for CollectionView and it looks like the item view event forwarding should be set up before the item views are rendered. but i added a test to see if it was working correctly and it isn't. I'll keep digging in to this.

the plan, right now, is to change things so that the item view event forwarding is set up before the item view is rendered or added to the the collection view.

@derickbailey derickbailey added a commit that referenced this issue Dec 2, 2012

@derickbailey derickbailey another spec to show itemview 'render' event is forwarded through the…
… collectionview as 'itemview:render' correctly. #229

derickbailey commented Dec 2, 2012

the spec issue was bad setup for the spec. fixed the setup and the specs pass. the "itemview:render" event is properly forwarded from all item views that are rendered from a collection view.

is this ticket still valid, @kevindente? is there something i'm missing in what you need, or can i close it?


kevindente commented Dec 2, 2012

Looks to me like your change closes out this ticket. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment