MAF.messages Singleton

MAF.messages provides a persist key-based hash table to store messages combined with broadcast events when hash data is added or updated.

MAF.messages()

Example

var valueChanged = function (event) {
    log("Key: ", event.payload.key, " changed value to: ",event.payload.value);
 };
 valueChanged.subscribeTo(MAF.messages, MAF.messages.eventType);
 MAF.messages.store('numbers', [9,15,1,30]);

Methods

exists(key) → {Boolean}

Checks if a given key exists.

Parameters:

NameTypeDescription
keyString

Key to look for in the Hash table.

Returns:

If the key exists 'true' will be returned.

fetch(key) → {Mixed}

Retrieves the value associated with the given key from the hash table. Returns undefined if not found.

Parameters:

NameTypeDescription
keyString

Key to look for in the Hash table.

Returns:

The value associated with the given key.

forEach(fn, scope)

Iterate through all keys in the hash table.

Parameters:

NameTypeDescription
fnfunction

Key will be the parameter.

scopeMixed

Scope in which to run the function in.

Example

MAF.messages.forEach(function(key){
   if (key === 'example')
      console.log('This key has already data stored.', MAF.messages.fetch(key));
});

remove(key)

Deletes the value associated with the given key from the hash table. Notifies all event listeners for the given key that the value has changed (deleted).

Parameters:

NameTypeDescription
keyString

Deletes the value associated with the given key.

reset()

Resets the hash table and list of event listeners to null.

store(key, value)

Updates the value associated with the given key in the hash table. Notifies all event listeners for the given key with the new value.

Parameters:

NameTypeDescription
keyString

Updates the value associated with the given key.

valueMixed

Value to store on the given key. The value can be an object, array, or any primitive type.

Events

onBroadcast

Fired when values in the messages hash table is changed.