4
votes

Can someone clarify the correct usage of events and commands with the following signup and login example?

A typical app my need functions to

  • display the signup form
  • execute the signup
  • show a success page

and

  • display the login form
  • execute login
  • handle successful login

How could this be mapped to Backbone/Marionette Events?

How could this be mapped to WreqR commands?

I'm struggeling with the naming of the events:

e.g. onShowSignUp:

Isn't this an event that should be triggered AFTER the signup form is displayed? How should the event triggering the showSignUpForm or the showLoginForm function be called?

1

1 Answers

1
votes

Events and commands are designed to decouple modules from each other.

Module A doesn't know explicitly about module B, it only emits an event on application.vent for example signup for submitted, then B module listens for this event and redirects the browser to success page.

The same with commands, but more suited for situation where You need some kind of information to proceed, for example after a successful login retrieving the username of who logged in. If You don't want to put the dependency everywhere how to get the user credentials, register a command in module A, and then module B and C can retrieve it decoupled from its concrete implementation.