Signal
Signal Interface returned from createSignal.
Type Parameters
| Type Parameter | Default type |
|---|---|
Subject | - |
Observable | Subject |
Properties
| Property | Type | Description |
|---|---|---|
name? | string | - |
size | number | Internal 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
| Parameter | Type | Description |
|---|---|---|
observer | Observer<Observable> | A function to be called when there is a new signal |
options? | { context?: unknown; signal?: AbortSignal; } | - |
options.context? | unknown | - |
options.signal? | AbortSignal | - |
Returns
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
| Parameter | Type | Description |
|---|---|---|
observer | Observer<Observable> | A function to be called when there is a new signal |
options? | { context?: unknown; signal?: AbortSignal; } | - |
options.context? | unknown | - |
options.signal? | AbortSignal | - |
Returns
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
| Parameter | Type |
|---|---|
subject | Subject |
Returns
void
Call Signature
emit(subject?): void;
Parameters
| Parameter | Type |
|---|---|
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
| Parameter | Type | Description |
|---|---|---|
observer | Observer<Observable> | the observer was passed in earlier |
Returns
void