Skip to content

bocodigitalmedia/boco-dispatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

boco-dispatch

Dispatcher (ala Flux)

Installation

npm install boco-dispatch

Usage

BocoDispatch = require 'boco-dispatch'

dispatcher = new BocoDispatch.Dispatcher

cb1 = dispatcher.register (dispatch) ->
  if dispatch.message is 'hello'
    dispatch.waitFor cb3, cb2
    console.log 1, dispatch.payload.message

cb2 = dispatcher.register (dispatch) ->
  if dispatch.message is 'hello'  
    console.log 2, dispatch.payload.message

cb3 = dispatcher.register (dispatch) ->
  if dispatch.message is 'hello'
    console.log 3, dispatch.payload.message

cb4 = dispatcher.register (dispatch) ->
  if dispatch.message is 'goodbye'
    console.log 4, dispatch.payload.message

dispatcher.dispatch message: 'hello'
dispatcher.dispatch message: 'goodbye'

# =>
# 3 hello
# 2 hello
# 1 hello
# 4 goodbye

Releases

No releases published

Packages

No packages published