Interface: Signal<T>
Signal Interface returned from createSignal.
Type parameters
| Name |
|---|
T |
Properties
name
• Optional name: string
size
• size: number
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
Remarks
If the context is not provided it assumes the observer has been
bind before it is passed to the signal.
Parameters
| Name | Type | Description |
|---|---|---|
observer | Observer<T> | A function to be called when there is a new signal |
context? | unknown | Optional context for the observer, you can skip it if observer has already been bind |
Returns
function to detach the observer from the signal see DetachFn
addOnce
▸ addOnce(observer, context?): Detach
Add a new observer and got automatically detached immediately after the first signal.
Remarks
If the context is not provided it assumes the observer has been
bind
before it is passed to the signal.
Parameters
| Name | Type | Description |
|---|---|---|
observer | Observer<T> | A function to be called when there is a new signal |
context? | unknown | Optional context for the observer, you can skip it if observer has already been bind |
Returns
function to detach the observer from the signal see DetachFn
emit
▸ emit(): void
Emit signal.
Remarks
It will print a warning when it is trying to emit a signal when there is no observer.
Returns
void
▸ emit(subject): void
Parameters
| Name | Type |
|---|---|
subject | T |
Returns
void
remove
▸ remove(observer): void
Remove the observer from the signal construct.
Please use the returned function from add instead
Parameters
| Name | Type | Description |
|---|---|---|
observer | Observer<T> | the observer was passed in earlier |
Returns
void