Mufa

المُفَوّض  or The MUFAwwad is the engine of this library. it handles creation of Mufa instances.

new Mufa()
Author: Abdennour <http://abdennoor.com>
Properties
registry (Registry) : The store
Example
import {on, fire} from 'mufa';
// publish
setTimeout(() => {
  fire('sendEmoji', '👏')
}, 1000)  ;
// subscribe
on('sendEmoji', (emoji) => console.log(emoji));
Static Members
sub(event, callback, once = false)
pub(event, data)
unsub(subscriptions)

on

Subscribe to event and save the callback to be running when the event is published (fired).

It is an alias of mufa.sub

on(event: String, callback: Function): Subscription
Parameters
event (String) event name
callback (Function) callback to be running when the event is published
Returns
Subscription: Subscription's info

one

Subscribe once to event and save the callback to be running when the event is published (fired)

It is almost an alias of mufa.sub.

one(event: String, callback: Function): Subscription
Parameters
event (String) event name
callback (Function) callback to be running when the event is published
Returns
Subscription: Subscription's info

fire

Publish (fire) an event & notify event's subscribers immediatly.

It is an alias of mufa.pub

fire(event: String, data: any): undefined
Parameters
event (String) The event name
data (any) message(s) to be sent to subscribers
Returns
undefined:

off

Cancel the subscription which was done with "sub" or "one" or "once" It is an alias of mufa.unsub.

off(subscriptions: Subscription): Array<Subscription>
Parameters
subscriptions (Subscription) One subscription for each argument
Returns
Array<Subscription>: arguments

Subscription

Subscription

Type: Object

Properties
id (String) : The ID of subscription
event (String) : The event name of subscription
callback (Function) : The action to do when the event is fired