Skip to main content

reference

Types

function reference<GValue>(
getValue: IGetReferenceValue<GValue>,
): IObservable<GValue>
interface IGetReferenceValue<GValue> {
(): GValue;
}

Definition

Creates an Observable, which on subscribe, will call getValue and emits the returned value.

Diagram

Example

Deferred usage of the variable 'value'

// let's assume we don't know yet the value to assign
let value: number;

const subscribe = reference(() => value);

const destination = (value: number) => {
console.log(value);
};

// LATER
value = 1;
subscribe(destination); // output '1'

value = 2;
subscribe(destination); // output '2'