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, options?): Detach;

Add a new observer to receive the signal

Parameters​

ParameterTypeDescription
observerObserver<Observable>A function to be called when there is a new signal
options?{ context?: unknown; signal?: AbortSignal; }-
options.context?unknown-
options.signal?AbortSignal-

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, options?): 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
options?{ context?: unknown; signal?: AbortSignal; }-
options.context?unknown-
options.signal?AbortSignal-

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.


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


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


clearBuffers()​

clearBuffers(): void;

Clear the buffers (if any)

Returns​

void