# Namespace: pubSub

## pubSub

Publish / Suscribe event system

### Example

    pubSub.init(
        {
            "MY_EVENT_1": "myevent1",
            "MY_EVENT_2": "myevent2"
        }
    );

    pubSub.on( pubSub.MY_EVENT_1, callback );
    pubSub.off( pubSub.MY_EVENT_1, callback );
    pubSub.fire( pubSub.MY_EVENT_1 );

    // You can send data along with the event:
    pubSub.on( pubSub.MY_EVENT_2, data => {
         console.log(data.myProp)
    } );

    pubSub.fire( pubSub.MY_EVENT_2, {myProp: 'test'} );

### Methods

#### <static> add(eventsNames)

  Add events name

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `eventsNames` | Object | String | [ "name1", "name2" ] or "name1"

  ##### Returns:

  Type
    PubSub

#### <static> fire(eventName [, data])

  Fire an event

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `eventName` | String |  |
  `data` | Object | <optional> | Data to be send to the callback functions

  ##### Returns:

  Type
    PubSub

#### <static> init(eventsNames)

  Initialize all events name

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `eventsNames` | Object | { "name1": val, "name2": val2, ... }

  Deprecated:
    - Use pubSub.add( [] ) instead

  ##### Returns:

  Type
    PubSub

#### <static> off(eventName, callback)

  Unbind an event

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `eventName` | String |
  `callback` | function |

  ##### Returns:

  Type
    PubSub

#### <static> on(eventName, callback)

  Bind an event

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `eventName` | String |
  `callback` | function | (data) => {}

  ##### Returns:

  Type
    PubSub

#### Search results