Actions

Summary

In the Flux {Architecture.md}, almost every user action is translated into an Action object and fired globally. Stores in the app observe these actions and perform business logic. This loose coupling means that your packages can observe actions and perform additional logic, or fire actions which the rest of the app will handle.

In Reflux, each {Action} is an independent object that acts as an event emitter. You can listen to an Action, or invoke it as a function to fire it.

Action Scopes

N1 is a multi-window application. The scope of an Action dictates how it propogates between windows.

  • Global: These actions can be listened to from any window and fired from any window. The action is sent from the originating window to all other windows via IPC, so they should be used with care. Firing this action from anywhere will cause all listeners in all windows to fire.
  • Main Window: You can fire these actions in any window. They'll be sent to the main window and triggered there.
  • Window: These actions only trigger listeners in the window they're fired in.

Firing Actions

Actions.queueTask(new ChangeStarredTask(thread: @_thread, starred: true))

Listening for Actions

If you're using Reflux to create your own Store, you can use the listenTo convenience method to listen for an Action. If you're creating your own class that is not a Store, you can still use the listen method provided by Reflux:

setup: ->
  @unlisten = Actions.onNewMailDeltas.listen(@onNewMailReceived, @)

onNewMailReceived: (data) ->
  console.log("You've got mail!", data)

teardown: ->
  @unlisten()

results matching ""

    No results matching ""