Module lib.container.observable

Create an Observable value (object).

An observable value notifies registered observers each time the value is set.

Functions

Observable:set (value, quiet) Set the value
Observable:__call () Return the current value (short hand for the 'value' method)
Observable:value () Return the current value
Observable:register (observer, handler) Register an observer of value changes

An observer is identified by a key which can be any type (number, string, table, etc).

Observable:unregister (observer) Unregister an observer of value changes
Observable:notify_observers () Notify registered observers of current value (normally called by `set`).


Functions

Observable:set (value, quiet)
Set the value

Parameters:

  • value anything New value for observable.
  • quiet boolean If true, do not notify observers.
Observable:__call ()
Return the current value (short hand for the 'value' method)

Returns:

    anything
Observable:value ()
Return the current value

Returns:

    anything
Observable:register (observer, handler)
Register an observer of value changes

An observer is identified by a key which can be any type (number, string, table, etc). Registering an observer replaces any previous registration associated with that key.

The handler is a function which is passed one argument, the new value. If `handler` is not provided it is assumed that the `observer` is an object with a `notify` method and the `notify` method is called with the new value.

Parameters:

  • observer anything Identity of observer.
  • handler function New value callback, optional.
Observable:unregister (observer)
Unregister an observer of value changes

Parameters:

  • observer anything Identity of observer.

Returns:

    boolean true if the observer was known and unregistered.
Observable:notify_observers ()
Notify registered observers of current value (normally called by `set`).
generated by LDoc 1.4.6 Last updated 2021-01-11 12:10:11