Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between Marionette's Application.execute and Application.trigger methods?

According to the docs, Marionette.Application provides three "action" methods:

  1. Application.execute - execute some action but register it first with MyApp.command('action', function () {});
  2. Application.request - is like Application.execute but can return something
  3. Application.trigger - is the same as Application.execute.

What's the difference between Application.trigger and Application.execute?

like image 890
Павел Тявин Avatar asked Jan 11 '23 07:01

Павел Тявин


1 Answers

When A calls execute, it orders B to do something. There's a somewhat direct link: one orders, the other executes (i.e. something must happen).

Triggers simply trigger an event to indicate something happened in the application. Other sections of the code might be listening for that event and react to it, but it also possible that no one is listening (so nothing will happen). Basically, by using triggers you can easily implement a publish/subscribe pattern in your application.

For completeness, there's also a triggerMethod call in Marionnette: it triggers the "some:event" signal, but also executes the onSomeEvent function if applicable. For example, myView.triggerMethod("some:event") will trigger the "some:event" within the myView scope and call myView.onSomeEvent.

like image 128
David Sulc Avatar answered Apr 27 '23 08:04

David Sulc