Where to use event aggregator in puppet?

I want to implement a special instance of an event event aggregator with requirejs as an explanator here

Looking at the examples here and in the docs, I noticed that the calls to vent.on and vent.trigger are mostly used in views. Then my template will look like this:

define(['marionette', 'vent'], function (Marionette, vent) { return Marionette.ItemView.extend({ initialize: function () { //bind this.listenTo(vent, 'mycustomevent', this.myMethod); //trigger vent.trigger('viewinit', ...); } }); }); 

Is this template correct (views are responsible for managing aggregator events) or should I use it in models and collections?

+4
source share
1 answer

An event aggregator is just a pub / subsystem for communication.

As for β€œwhat should go,” I would suggest the following in most cases:

  • displays trigger events (depending on what the user clicked, for example) Controllers
  • listen and respond to events (deleting a model, for example)

Of course, there are many ways to use the event aggregator, but when working with views, the above method is suitable for most cases.

Using an event aggregator is also useful for managing routing events and removing duplication (see the section "Implementing Routing" here: http://samples.leanpub.com/marionette-gentle-introduction-sample.pdf )

+5
source

Source: https://habr.com/ru/post/1481889/


All Articles