Skip to content

Commit

Permalink
feat(signal): getSignalObject
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Feb 26, 2022
1 parent 5bf82b3 commit b38954c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions package/signal/src/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {SignalObject} from './type';

/**
* Signal stack database.
*/
const signalStack: {
[SignalName in keyof VatrSignals]?: SignalObject<SignalName>;
} = {};

/**
* Access to signal option, Make new signal with default options if not exist.
*/
export function getSignalObject<SignalName extends keyof VatrSignals>(
signalName: SignalName,
): SignalObject<SignalName> {
if (!signalStack[signalName]) {
signalStack[signalName] = {
disabled: false,
priorityListenerList: [],
listenerList: [],
};
}
return signalStack[signalName] as unknown as SignalObject<SignalName>;
}

0 comments on commit b38954c

Please sign in to comment.