@pexip/signal
Interfaces
Type Aliases
Detach
Ƭ Detach: () => void
Type declaration
▸ (): void
A detach function to remove its observer from the Signal construct when it is called.
Example
interface Message {
type: string;
payload: any;
}
const messageSignal = createSignal<Message>();
const messageHandler = (message: Message) => {
logger.info({message});
};
const detachMessageSignal = connectedSignal.add(messageHandler);
// Wire the signal to WebSocket onMessage
ws.onmessage((message) => {
messageSignal.emit(message);
});
// Later there is no need to listen the message event, or the context is
about to be abandoned
// Call the detach function to remove the listener from messageSignal
detachMessageSignal();
Returns
void
ExtractSignalsState
Ƭ ExtractSignalsState<T
>: { [K in keyof T]: T[K] extends Signal<infer S> ? S | undefined : undefined }
Type parameters
Name | Type |
---|---|
T | extends Signal <unknown >[] |
Observer
Ƭ Observer<T
>: (subject
: T
) => void
| Promise
<void
>
Type parameters
Name |
---|
T |
Type declaration
▸ (subject
): void
| Promise
<void
>
Generic Observer function to handle the emitted signal.
Parameters
Name | Type |
---|---|
subject | T |
Returns
void
| Promise
<void
>
SignalVariant
Ƭ SignalVariant: "generic"
| "behavior"
| "replay"
Variant of available signal
Functions
combine
▸ combine<T
>(...signals
): Signal
<ExtractSignalsState
<T
>>
Type parameters
Name | Type |
---|---|
T | extends Signal <unknown >[] |
Parameters
Name | Type |
---|---|
...signals | T |
Returns
Signal
<ExtractSignalsState
<T
>>
createSignal
▸ createSignal<T
>(options?
): Signal
<T
>
A function to create a new Signal
Example
const defaultSignal = createSignal<number>();
// Behavior Signal, always emitted with the latest value when added
const behaviorSignal = createSignal<number>({variant: 'behavior'});
// Replay Signal, replay the last values when added according to `bufferSize`
const replaySignal = createSignal<number>({variant: 'replay'});
Type parameters
Name | Type |
---|---|
T | undefined |
Parameters
Name | Type | Description |
---|---|---|
options | SignalOptions | See SignalOptions |
Returns
Signal
<T
>
setFlags
▸ setFlags(newFlags
): void
Parameters
Name | Type |
---|---|
newFlags | Flags |
Returns
void
setLogger
▸ setLogger(newLogger
): void
Parameters
Name | Type |
---|---|
newLogger | Logger |
Returns
void