Manual Reference Source Test
import Observable from 'src/modules/observable.js'
public class | source

Observable

Direct Subclass:

Identity, IdentityNative

Minimal observable class

Constructor Summary

Public Constructor
public

Observable constructor

Method Summary

Public Methods
public

notify(type: string, data: *)

Notify all observers of specified event type

public

on(type: string, callback: Function): Function

Register callback to be called with events of specified type

Public Constructors

public constructor() source

Observable constructor

Public Methods

public notify(type: string, data: *) source

Notify all observers of specified event type

Params:

NameTypeAttributeDescription
type string

Event type

data *

Event data

public on(type: string, callback: Function): Function source

Register callback to be called with events of specified type

Callback will be called with an argument depending on the type of event.

Params:

NameTypeAttributeDescription
type string

Event type

callback Function

Event callback function

Return:

Function

Function to be called to unregister this callback

Example:

const observable = new Observable();
const off = observable.on('foo', (data) => {
  console.log(`Foo!`, data);
});

// To stop observing events at a later time:
off();