Message Bank
Subscribable message bank.
MessageBank behaves subtly different than a standard message bus. Subscribing to a message type that has been dispatched previously the callback function will fire immediately.
API
MessageBank(options:Object)
Creates a new message bank instance with predefined options.
var bank = ;
options.setup(callback:Function)
Alias for bank.setup(func)
var bank = { } ;
options.config(options:Object)
Alias for bank.config()
var bank = config: type: 'SUPER' { } ;
Bank().setup(callback:Function)
Calls callback function immediatly with MessageBank instance as function context. Inert function by default, provides entry point additional setup behavior not default to MessageBox
bank;
Bank().config(type:String, config:Object)
Also: Bank().config(config:Object)
Bank().config(config:ObjectArray)
Method for configuring how dispatched data is handled for specific dispatch type. Currently only defines transform config option, but this is a good place to enter custom configuration to be used in a custom parse function.
config.transform(callback:Function)
By default transform config is called with data and options as arguments during the parse phase of a dispatch call.
bank;
Bank().dispatch(type:String, data:Object, options:Object)
Also: Bank().dispatch(dispatch:Object)
Bank().dispatch(dispatch:ObjectArray)
Dispatches a payload of data to the MessageBank, any subscriptions matching the payload type will be called.
bank;
Bank().subscribe(type:String, callback:Function, options:Object)
Subscribe to a specific type of dispatch payload, if previous payload exists callback will be called immediately. Subscribe returns an id that can used to unsubscribe later.
Subscribing to the *
or ALL
type will respond to all dispatches. Bank().subscribe(callback:Function, opts:Options)
will do the same.
bank
options.immediate
By default subscriptions will be called immediately if a payload of that type exists, setting immediate:false
will hold of on calling until the next dispatch.
bank;
Bank().unsubscribe(id:Integer)
Unsubscribe from a dispatch type using subscription ID returned when defining a subscription.
var id = bank;
Bank().parse(type:String, data:Object, options:Object)
Internal function for manipulating dispatched data expecting a result of { data: {}, options: {} }
By default parse runs any transform configs, but it can be overwriten for custom behavior.