Home Reference Source Test
import Messager from 'seed-engine/src/utils/Messager.js'
public class | source

Messager

A messager is a managed dictionary that notifies listeners when specific entries in the dictionary are updated. The messager contains functions for setting, getting, listening and notifying of data changes.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

data: {}

public
public

listeners: {}

Method Summary

Public Methods
public

get(key: string): *

Returns the data at a location in the dictionary specified by the key.

public

notify(key: string)

Notifies all listeners currently waiting on updates at the location of the dictionary key.

public

set(key: string, data: *)

Updates the data at a specific location in the Messager storage dictionary.

public

watch(key: string, callback: function, notifyNow: boolean): function

Listens to a position in the dictionary for updates.

Public Constructors

public constructor() source

Public Members

public data: {} source

public listenerIDCounter: number source

public listeners: {} source

Public Methods

public get(key: string): * source

Returns the data at a location in the dictionary specified by the key.

Params:

NameTypeAttributeDescription
key string

Dictionary key name.

Return:

*

public notify(key: string) source

Notifies all listeners currently waiting on updates at the location of the dictionary key.

Params:

NameTypeAttributeDescription
key string

Dictionary key name.

public set(key: string, data: *) source

Updates the data at a specific location in the Messager storage dictionary. If there are listeners, notify them.

Params:

NameTypeAttributeDescription
key string

Dictionary key name.

data *

Data to set.

public watch(key: string, callback: function, notifyNow: boolean): function source

Listens to a position in the dictionary for updates. The callback passed to the function is called whenever the position defined by the dictionary key is updated.

By default, notifies the callback of the current data upon watching.

Params:

NameTypeAttributeDescription
key string

Dictionary key name.

callback function

Callback function to trigger.

notifyNow boolean

Default: true. Trigger the callback now.

Return:

function

A callback function to de-register from watching data at the key location.