backbone.js - Where to use event aggregator in backbone marionette? -
i want implement custom vent event aggregator instance requirejs explainer here
looking @ examples here , in docs, i've seent calls vent.on , vent.trigger used in views. pattern be:
define(['marionette', 'vent'], function (marionette, vent) { return marionette.itemview.extend({ initialize: function () { //bind this.listento(vent, 'mycustomevent', this.mymethod); //trigger vent.trigger('viewinit', ...); } }); });
is pattern correct (views responsible managing aggregator events) or should use on models , collections?
the event aggregator pub/sub system communication.
regarding "what should go where", i'd suggest following in cases:
- views trigger events (according user has clicked, e.g.)
- controllers listen , react events (deleting model, e.g.)
of course, there many ways use event aggregator, when dealing views, above method fits use cases.
using event aggregator useful manage routing events , remove duplication (see section "implementing routing" here: http://samples.leanpub.com/marionette-gentle-introduction-sample.pdf )
Comments
Post a Comment