From b38954cf4ae1c24eaaa79ecf513995a4678814ee Mon Sep 17 00:00:00 2001 From: Ali Mihandoost Date: Sat, 26 Feb 2022 16:19:37 +0330 Subject: [PATCH] feat(signal): getSignalObject --- package/signal/src/core.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 package/signal/src/core.ts diff --git a/package/signal/src/core.ts b/package/signal/src/core.ts new file mode 100644 index 000000000..5bed01e56 --- /dev/null +++ b/package/signal/src/core.ts @@ -0,0 +1,24 @@ +import {SignalObject} from './type'; + +/** + * Signal stack database. + */ +const signalStack: { + [SignalName in keyof VatrSignals]?: SignalObject; +} = {}; + +/** + * Access to signal option, Make new signal with default options if not exist. + */ +export function getSignalObject( + signalName: SignalName, +): SignalObject { + if (!signalStack[signalName]) { + signalStack[signalName] = { + disabled: false, + priorityListenerList: [], + listenerList: [], + }; + } + return signalStack[signalName] as unknown as SignalObject; +}