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:
Name Type Description key String 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:
Name Type Description key String 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:
Name Type Description fn function Key will be the parameter.
scope Mixed 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:
Name Type Description key String 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:
Name Type Description key String Updates the value associated with the given key.
value Mixed 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.