Class: Observable

utils/NanoHooks.Observable()

Minimal observable to register and run for any given names. As opposed to Events (i.e. nanoevents) these also run in sync mode and thus in registered order. If you need async functionality then you might consider an event emitter like nanoevents instead.

Constructor

new Observable()

Source:

Members

src :Map.<string, Array.<function()>>

The underlying data structure is a map of function arrays. It's a public member, because you may need to manually access it for whatever reason.

Type:
  • Map.<string, Array.<function()>>
Source:

Methods

off(name, fn)

Unregister a hook by given name and function. Note that reference check is strict equal, so it needs to be the exact same function. If you create dynamic functions a lot, you may rather use the returned function from on to unregister the given functions.

Parameters:
Name Type Description
name string
fn function
Source:

on(name, fn) → {function}

Register a new hook by name. Async functions are possible but discouraged as there will be race conditions.

Parameters:
Name Type Description
name string
fn function
Source:
Returns:

call to unregister hook

Type
function

run(name, …args)

Run all registered hooks for a given name. Args are optional

Parameters:
Name Type Attributes Description
name string
args * <repeatable>
Source: