Skip to main content

Signal

Signal Interface returned from createSignal.

Type Parameters

Type ParameterDefault type
Subject-
ObservableSubject

Properties

PropertyTypeDescription
name?string-
sizenumberInternal A function to get the current size of observers for internal testing purpose.

Methods

add()

add(observer, context?): Detach;

Add a new observer to receive the signal

Parameters

ParameterTypeDescription
observerObserver<Observable>A function to be called when there is a new signal
context?unknownOptional context for the observer, you can skip it if observer has already been bind

Returns

Detach

function to detach the observer from the signal see DetachFn

Remarks

If the context is not provided it assumes the observer has been `bind` before it is passed to the signal.


addOnce()

addOnce(observer, context?): Detach;

Add a new observer and got automatically detached immediately after the first signal.

Parameters

ParameterTypeDescription
observerObserver<Observable>A function to be called when there is a new signal
context?unknownOptional context for the observer, you can skip it if observer has already been bind

Returns

Detach

function to detach the observer from the signal see DetachFn

Remarks

If the context is not provided it assumes the observer has been `bind` before it is passed to the signal.


emit()

Call Signature

emit(): void;

Emit signal.

Returns

void

Remarks

It will print a warning when it is trying to emit a signal when there is no observer.

Call Signature

emit(subject): void;
Parameters
ParameterType
subjectSubject
Returns

void

Call Signature

emit(subject?): void;
Parameters
ParameterType
subject?Subject
Returns

void


remove()

remove(observer): void;

Internal

Remove the observer from the signal construct. Please use the returned function from Signal.add instead

Parameters

ParameterTypeDescription
observerObserver<Observable>the observer was passed in earlier

Returns

void