Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

backbone.js - working with the event dispatcher var dispatcher = _.clone(Backbone.Events)

In backbone.js documentation it says:

To make a handy event dispatcher that can coordinate events among different areas of your application: var dispatcher = _.clone(Backbone.Events)

Can anyone explain how to implement the dispatcher to communicate from one view to another? Where do I have to place the code in my app?

like image 463
joafeldmann Avatar asked Feb 07 '12 12:02

joafeldmann


People also ask

How backbone js works?

BackboneJS provides various building blocks such as models, views, events, routers and collections for assembling the client side web applications. When a model changes, it automatically updates the HTML of your application. BackboneJS is a simple library that helps in separating business and user interface logic.

What is backbone in programming?

Backbone. js is a model view controller (MVC) Web application framework that provides structure to JavaScript-heavy applications. This is done by supplying models with custom events and key-value binding, views using declarative event handling and collections with a rich application programming interface (API).

What is module in Backbone JS?

js respectively. The rest of your application code should be divided into modules that can live under their own modules directory. A module is an encapsulated group of structures (for the purposes of our post, Backbone structures) that work cohesively to provide a subset of functionality in your application.

Which function has to be used when you want to trigger the event only once before being removed?

js Event once() The event once method is just like event on method but it causes the bound callback to only fire once before being removed.


1 Answers

Here is a good article about using an event aggregator.

Can anyone explain how to implement the dispatcher to communicate from one view to another? Where do I have to place the code in my app?

You will probably have some kind of App Controller object, which will control the flow of the app, creating views, models, etc. This is also a good place for the event aggregator.

From my point of view, I think that article explains it pretty well.

like image 75
Paul Hoenecke Avatar answered Sep 24 '22 01:09

Paul Hoenecke