@alwatr/signal 0.29.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,33 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.31.0](https://github.com/AliMD/alwatr/compare/v0.30.0...v0.31.0) (2023-05-08)
7
+
8
+ ### Bug Fixes
9
+
10
+ - new logger api ([9d83a7d](https://github.com/AliMD/alwatr/commit/9d83a7dc5c103bc3bb4282dacfd85fa998915300))
11
+ - **signal:** dont receivePrevious when listener is disabled ([68ae207](https://github.com/AliMD/alwatr/commit/68ae207ce9ecf104922b24910d8dfcedb13acde7))
12
+ - **signal:** requestableContextProvider.getValue ([0a7111d](https://github.com/AliMD/alwatr/commit/0a7111da7b8eb004566922dc9b35edfc02a55147))
13
+
14
+ ### Features
15
+
16
+ - **signal:** new RequestableContext with state ([b8a8e55](https://github.com/AliMD/alwatr/commit/b8a8e550d3952863d85ba9d9d87513a668a9430d))
17
+
18
+ # [0.30.0](https://github.com/AliMD/alwatr/compare/v0.29.0...v0.30.0) (2023-03-06)
19
+
20
+ ### Bug Fixes
21
+
22
+ - **signal:** NextCycle with own detail ([01f3c79](https://github.com/AliMD/alwatr/commit/01f3c79500927f6384a33abcc9b0cb2355794b3e))
23
+ - **signal:** nodejs compatibility ([69d8a60](https://github.com/AliMD/alwatr/commit/69d8a60ad64d44ee7c3ced002e702f13408a5a50))
24
+ - **signal:** requestableContextConsumer bind issue ([66467f6](https://github.com/AliMD/alwatr/commit/66467f6e5681d84d7f2e0b353206d4bb579b26f2))
25
+ - **signal:** requestContext dispatch issue ([e937ebd](https://github.com/AliMD/alwatr/commit/e937ebd3a90fc6a9946f5c35ef4f6f40b6ab4b00))
26
+
27
+ ### Features
28
+
29
+ - **signal:** add untilChange for contextProvider ([cb44916](https://github.com/AliMD/alwatr/commit/cb4491698fd5ddfbe055032fc2cb50691de31194))
30
+ - **signal:** defineCommand return ListenerSpec ([21fecac](https://github.com/AliMD/alwatr/commit/21fecacb6aa9423da9e3c177a4bbc59952d94e35))
31
+ - **signal:** dispatch NextCycle option ([b30eb31](https://github.com/AliMD/alwatr/commit/b30eb316d92f594034fc40d195c4033e38e4d2e2))
32
+
6
33
  # [0.29.0](https://github.com/AliMD/alwatr/compare/v0.28.0...v0.29.0) (2023-02-10)
7
34
 
8
35
  ### Bug Fixes
@@ -20,6 +20,6 @@ export declare const commandHandler: {
20
20
  */
21
21
  readonly define: <TArgument extends import("@alwatr/type").StringifyableRecord, TReturn extends import("@alwatr/type").Stringifyable>(signalId: string, signalProvider: import("./type.js").ProviderFunction<TArgument & {
22
22
  _callbackSignalId?: string | undefined;
23
- }, TReturn>, options?: Partial<Pick<import("./type.js").ProviderOptions, "debounce">>) => void;
23
+ }, TReturn>, options?: Partial<Pick<import("./type.js").ProviderOptions, "debounce">>) => import("./type.js").ListenerSpec;
24
24
  };
25
25
  //# sourceMappingURL=command-handler.d.ts.map
@@ -42,6 +42,16 @@ export declare const contextProvider: {
42
42
  * ```
43
43
  */
44
44
  readonly expire: (signalId: string) => void;
45
+ /**
46
+ * Waits until the context value changes.
47
+ *
48
+ * Example:
49
+ *
50
+ * ```ts
51
+ * const newProductList = await contextProvider.untilChange<ProductListType>('product-list');
52
+ * ```
53
+ */
54
+ readonly untilChange: <T_2 extends Stringifyable>(signalId: string) => Promise<T_2>;
45
55
  /**
46
56
  * Bind this interface to special context.
47
57
  *
@@ -51,7 +61,7 @@ export declare const contextProvider: {
51
61
  * const productListProvider = contextProvider.bind<ProductListType>('product-list');
52
62
  * ```
53
63
  */
54
- readonly bind: <T_2 extends Stringifyable>(contextId: string) => {
64
+ readonly bind: <T_3 extends Stringifyable>(contextId: string) => {
55
65
  /**
56
66
  * Context signal Id.
57
67
  */
@@ -70,7 +80,7 @@ export declare const contextProvider: {
70
80
  * }
71
81
  * ```
72
82
  */
73
- readonly getValue: () => T_2 | undefined;
83
+ readonly getValue: () => T_3 | undefined;
74
84
  /**
75
85
  * Set context value and send signal to all consumers.
76
86
  *
@@ -82,7 +92,7 @@ export declare const contextProvider: {
82
92
  * productListProvider.setValue(newProductList);
83
93
  * ```
84
94
  */
85
- readonly setValue: (detail: T_2, options?: Partial<import("./type.js").DispatchOptions> | undefined) => void;
95
+ readonly setValue: (detail: T_3, options?: Partial<import("./type.js").DispatchOptions> | undefined) => void;
86
96
  /**
87
97
  * Clear current context value without send signal to all consumers.
88
98
  *
@@ -95,6 +105,16 @@ export declare const contextProvider: {
95
105
  * ```
96
106
  */
97
107
  readonly expire: () => void;
108
+ /**
109
+ * Waits until the context value changes.
110
+ *
111
+ * Example:
112
+ *
113
+ * ```ts
114
+ * const newProductList = await productListProvider.untilChange();
115
+ * ```
116
+ */
117
+ readonly untilChange: () => Promise<T_3>;
98
118
  };
99
119
  };
100
120
  //# sourceMappingURL=context-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context-provider.d.ts","sourceRoot":"","sources":["src/context-provider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,aAAa,EAAiB,MAAM,cAAc,CAAC;AAEhE;;GAEG;AACH,eAAO,MAAM,eAAe;IAC1B;;;;;;;;;;;;;OAaG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;OAQG;0DACwC,MAAM;QAC/C;;WAEG;;QAGH;;;;;;;;;;;;;WAaG;;QAGH;;;;;;;;;;WAUG;;QAGH;;;;;;;;;;WAUG;;;CAGG,CAAC"}
1
+ {"version":3,"file":"context-provider.d.ts","sourceRoot":"","sources":["src/context-provider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,aAAa,EAAiB,MAAM,cAAc,CAAC;AAEhE;;GAEG;AACH,eAAO,MAAM,eAAe;IAC1B;;;;;;;;;;;;;OAaG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;;OAQG;0DACwC,MAAM;QAC/C;;WAEG;;QAGH;;;;;;;;;;;;;WAaG;;QAGH;;;;;;;;;;WAUG;;QAGH;;;;;;;;;;WAUG;;QAGH;;;;;;;;WAQG;;;CAGG,CAAC"}
@@ -1,4 +1,4 @@
1
- import { clearDetail, dispatch, getDetail } from './core.js';
1
+ import { clearDetail, dispatch, getDetail, untilNext } from './core.js';
2
2
  /**
3
3
  * Context provider interface.
4
4
  */
@@ -42,6 +42,16 @@ export const contextProvider = {
42
42
  * ```
43
43
  */
44
44
  expire: clearDetail,
45
+ /**
46
+ * Waits until the context value changes.
47
+ *
48
+ * Example:
49
+ *
50
+ * ```ts
51
+ * const newProductList = await contextProvider.untilChange<ProductListType>('product-list');
52
+ * ```
53
+ */
54
+ untilChange: untilNext,
45
55
  /**
46
56
  * Bind this interface to special context.
47
57
  *
@@ -95,6 +105,16 @@ export const contextProvider = {
95
105
  * ```
96
106
  */
97
107
  expire: clearDetail.bind(null, contextId),
108
+ /**
109
+ * Waits until the context value changes.
110
+ *
111
+ * Example:
112
+ *
113
+ * ```ts
114
+ * const newProductList = await productListProvider.untilChange();
115
+ * ```
116
+ */
117
+ untilChange: untilNext.bind(null, contextId),
98
118
  }),
99
119
  };
100
120
  //# sourceMappingURL=context-provider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context-provider.js","sourceRoot":"","sources":["src/context-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAC,MAAM,WAAW,CAAC;AAI3D;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B;;;;;;;;;;;;;OAaG;IACH,QAAQ,EAAE,SAAS;IAEnB;;;;;;;;;;OAUG;IACH,QAAQ,EAAE,QAAQ;IAElB;;;;;;;;;;OAUG;IACH,MAAM,EAAE,WAAW;IAEnB;;;;;;;;OAQG;IACH,IAAI,EAAE,CAA0B,SAAiB,EAAE,EAAE,CAAA,CAAC;QACpD;;WAEG;QACH,EAAE,EAAE,SAAS;QAEb;;;;;;;;;;;;;WAaG;QACH,QAAQ,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAwC;QAEhF;;;;;;;;;;WAUG;QACH,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAuC;QAE9E;;;;;;;;;;WAUG;QACH,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC;KAChC,CAAA;CACH,CAAC","sourcesContent":["import {clearDetail, dispatch, getDetail} from './core.js';\n\nimport type {Stringifyable, OmitFirstParam} from '@alwatr/type';\n\n/**\n * Context provider interface.\n */\nexport const contextProvider = {\n /**\n * Get context value.\n *\n * Return undefined if context not set before or expired.\n *\n * Example:\n *\n * ```ts\n * const currentProductList = contextProvider.getValue<ProductListType>('product-list');\n * if (currentProductList === undefined) {\n * // productList not set before or expired.\n * }\n * ```\n */\n getValue: getDetail,\n\n /**\n * Set context value and send signal to all consumers.\n *\n * Signal detail changed immediately without any debounce.\n *\n * Example:\n *\n * ```ts\n * contextProvider.setValue<ProductListType>('product-list', newProductList);\n * ```\n */\n setValue: dispatch,\n\n /**\n * Clear current context value without send signal to all consumers.\n *\n * new subscriber options.receivePrevious not work until new signal\n *\n * Example:\n *\n * ```ts\n * contextProvider.expire('product-list');\n * ```\n */\n expire: clearDetail,\n\n /**\n * Bind this interface to special context.\n *\n * Example:\n *\n * ```ts\n * const productListProvider = contextProvider.bind<ProductListType>('product-list');\n * ```\n */\n bind: <T extends Stringifyable>(contextId: string) =>({\n /**\n * Context signal Id.\n */\n id: contextId,\n\n /**\n * Get context value.\n *\n * Return undefined if context not set before or expired.\n *\n * Example:\n *\n * ```ts\n * const currentProductList = productListProvider.getValue();\n * if (currentProductList === undefined) {\n * // productList not set before or expired.\n * }\n * ```\n */\n getValue: getDetail.bind(null, contextId) as OmitFirstParam<typeof getDetail<T>>,\n\n /**\n * Set context value and send signal to all consumers.\n *\n * Signal detail changed immediately without any debounce.\n *\n * Example:\n *\n * ```ts\n * productListProvider.setValue(newProductList);\n * ```\n */\n setValue: dispatch.bind(null, contextId) as OmitFirstParam<typeof dispatch<T>>,\n\n /**\n * Clear current context value without send signal to all consumers.\n *\n * new subscriber options.receivePrevious not work until new signal\n *\n * Example:\n *\n * ```ts\n * productListProvider.expire();\n * ```\n */\n expire: clearDetail.bind(null, contextId),\n } as const),\n} as const;\n"]}
1
+ {"version":3,"file":"context-provider.js","sourceRoot":"","sources":["src/context-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAC,MAAM,WAAW,CAAC;AAItE;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B;;;;;;;;;;;;;OAaG;IACH,QAAQ,EAAE,SAAS;IAEnB;;;;;;;;;;OAUG;IACH,QAAQ,EAAE,QAAQ;IAElB;;;;;;;;;;OAUG;IACH,MAAM,EAAE,WAAW;IAEnB;;;;;;;;OAQG;IACH,WAAW,EAAE,SAAS;IAEtB;;;;;;;;OAQG;IACH,IAAI,EAAE,CAA0B,SAAiB,EAAE,EAAE,CAAA,CAAC;QACpD;;WAEG;QACH,EAAE,EAAE,SAAS;QAEb;;;;;;;;;;;;;WAaG;QACH,QAAQ,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAwC;QAEhF;;;;;;;;;;WAUG;QACH,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAuC;QAE9E;;;;;;;;;;WAUG;QACH,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC;QAEzC;;;;;;;;WAQG;QACH,WAAW,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAwC;KAC1E,CAAA;CACH,CAAC","sourcesContent":["import {clearDetail, dispatch, getDetail, untilNext} from './core.js';\n\nimport type {Stringifyable, OmitFirstParam} from '@alwatr/type';\n\n/**\n * Context provider interface.\n */\nexport const contextProvider = {\n /**\n * Get context value.\n *\n * Return undefined if context not set before or expired.\n *\n * Example:\n *\n * ```ts\n * const currentProductList = contextProvider.getValue<ProductListType>('product-list');\n * if (currentProductList === undefined) {\n * // productList not set before or expired.\n * }\n * ```\n */\n getValue: getDetail,\n\n /**\n * Set context value and send signal to all consumers.\n *\n * Signal detail changed immediately without any debounce.\n *\n * Example:\n *\n * ```ts\n * contextProvider.setValue<ProductListType>('product-list', newProductList);\n * ```\n */\n setValue: dispatch,\n\n /**\n * Clear current context value without send signal to all consumers.\n *\n * new subscriber options.receivePrevious not work until new signal\n *\n * Example:\n *\n * ```ts\n * contextProvider.expire('product-list');\n * ```\n */\n expire: clearDetail,\n\n /**\n * Waits until the context value changes.\n *\n * Example:\n *\n * ```ts\n * const newProductList = await contextProvider.untilChange<ProductListType>('product-list');\n * ```\n */\n untilChange: untilNext,\n\n /**\n * Bind this interface to special context.\n *\n * Example:\n *\n * ```ts\n * const productListProvider = contextProvider.bind<ProductListType>('product-list');\n * ```\n */\n bind: <T extends Stringifyable>(contextId: string) =>({\n /**\n * Context signal Id.\n */\n id: contextId,\n\n /**\n * Get context value.\n *\n * Return undefined if context not set before or expired.\n *\n * Example:\n *\n * ```ts\n * const currentProductList = productListProvider.getValue();\n * if (currentProductList === undefined) {\n * // productList not set before or expired.\n * }\n * ```\n */\n getValue: getDetail.bind(null, contextId) as OmitFirstParam<typeof getDetail<T>>,\n\n /**\n * Set context value and send signal to all consumers.\n *\n * Signal detail changed immediately without any debounce.\n *\n * Example:\n *\n * ```ts\n * productListProvider.setValue(newProductList);\n * ```\n */\n setValue: dispatch.bind(null, contextId) as OmitFirstParam<typeof dispatch<T>>,\n\n /**\n * Clear current context value without send signal to all consumers.\n *\n * new subscriber options.receivePrevious not work until new signal\n *\n * Example:\n *\n * ```ts\n * productListProvider.expire();\n * ```\n */\n expire: clearDetail.bind(null, contextId),\n\n /**\n * Waits until the context value changes.\n *\n * Example:\n *\n * ```ts\n * const newProductList = await productListProvider.untilChange();\n * ```\n */\n untilChange: untilNext.bind(null, contextId) as OmitFirstParam<typeof untilNext<T>>,\n } as const),\n} as const;\n"]}
package/core.d.ts CHANGED
@@ -19,7 +19,7 @@ export declare const getSignalObject: <T extends Stringifyable>(id: string) => S
19
19
  *
20
20
  * Used inside dispatch, Don't use it directly.
21
21
  */
22
- export declare const _callListeners: <T extends Stringifyable>(signal: SignalObject<T>) => void;
22
+ export declare const _callListeners: <T extends Stringifyable>(signal: SignalObject<T>, detail: T) => void;
23
23
  /**
24
24
  * Subscribe new signal listener to a signal, work like addEventListener.
25
25
  *
@@ -101,7 +101,7 @@ export declare const untilNext: <T extends Stringifyable>(signalId: string) => P
101
101
  * setContextProvider('content-change', async (requestParam) => await fetchNewContent(requestParam));
102
102
  * ```
103
103
  */
104
- export declare const setContextProvider: <TContext extends Stringifyable, TRquest extends Stringifyable>(signalId: string, signalProvider: ProviderFunction<TRquest, void | TContext>, options?: Partial<ProviderOptions>) => void;
104
+ export declare const setContextProvider: <TContext extends Stringifyable, TRquest extends Stringifyable = null>(signalId: string, signalProvider: ProviderFunction<TRquest, void | TContext>, options?: Partial<ProviderOptions>) => void;
105
105
  /**
106
106
  * Defines the command and dispatch returned value.
107
107
  *
@@ -120,7 +120,7 @@ export declare const setContextProvider: <TContext extends Stringifyable, TRques
120
120
  */
121
121
  export declare const defineCommand: <TArgument extends StringifyableRecord, TReturn extends Stringifyable>(signalId: string, signalProvider: ProviderFunction<TArgument & {
122
122
  _callbackSignalId?: string | undefined;
123
- }, TReturn>, options?: Partial<Pick<ProviderOptions, 'debounce'>>) => void;
123
+ }, TReturn>, options?: Partial<Pick<ProviderOptions, 'debounce'>>) => ListenerSpec;
124
124
  /**
125
125
  * Dispatch request context signal with requestParam as detail.
126
126
  *
package/core.d.ts.map CHANGED
@@ -1 +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sCAAuC,MAAM,kBAElE,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,sCAAuC,MAAM,eASlE,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,mFACnB,MAAM,wEAEP,QAAQ,eAAe,CAAC,KAChC,IAkBF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,mFACd,MAAM;;uBAEP,QAAQ,KAAK,eAAe,EAAE,UAAU,CAAC,CAAC,KAClD,YAuBF,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,8CACd,MAAM,oCAER,QAAQ,eAAe,CAAC,KAChC,IAGF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,qDACd,MAAM,iCAEhB,IAGF,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,0BAA0B,oFAI1B,MAAM,iDAqBlB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,aAAc,MAAM,KAAG,IAI9C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,aAAc,MAAM,KAAG,IAMhD,CAAC"}
package/core.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { createLogger, globalAlwatr } from '@alwatr/logger';
2
+ import { requestAnimationFrame } from '@alwatr/util';
2
3
  globalAlwatr.registeredList.push({
3
4
  name: '@alwatr/signal',
4
5
  version: _ALWATR_VERSION_,
@@ -42,14 +43,9 @@ export const getSignalObject = (id) => {
42
43
  *
43
44
  * Used inside dispatch, Don't use it directly.
44
45
  */
45
- export const _callListeners = (signal) => {
46
- logger.logMethodArgs('_callListeners', { signalId: signal.id, signalDetail: signal.detail });
47
- if (signal.detail === undefined) {
48
- logger.accident('_callListeners', 'no_signal_detail', 'signal must have a detail', {
49
- signalId: signal.id,
50
- });
51
- return;
52
- }
46
+ export const _callListeners = (signal, detail) => {
47
+ var _a;
48
+ (_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, '_callListeners', { signalId: signal.id, signalDetail: detail });
53
49
  const removeList = [];
54
50
  for (const listener of signal.listenerList) {
55
51
  if (listener.disabled)
@@ -57,7 +53,7 @@ export const _callListeners = (signal) => {
57
53
  if (listener.once)
58
54
  removeList.push(listener);
59
55
  try {
60
- const ret = listener.callback(signal.detail);
56
+ const ret = listener.callback(detail);
61
57
  if (ret instanceof Promise) {
62
58
  ret.catch((err) => logger.error('_callListeners', 'call_listener_failed', err, {
63
59
  signalId: signal.id,
@@ -84,12 +80,12 @@ export const _callListeners = (signal) => {
84
80
  * ```
85
81
  */
86
82
  export const subscribe = (signalId, listenerCallback, options = {}) => {
87
- var _a, _b, _c, _d;
83
+ var _a, _b, _c, _d, _e;
88
84
  (_a = options.once) !== null && _a !== void 0 ? _a : (options.once = false);
89
85
  (_b = options.disabled) !== null && _b !== void 0 ? _b : (options.disabled = false);
90
- (_c = options.receivePrevious) !== null && _c !== void 0 ? _c : (options.receivePrevious = 'AnimationFrame');
86
+ (_c = options.receivePrevious) !== null && _c !== void 0 ? _c : (options.receivePrevious = 'NextCycle');
91
87
  (_d = options.priority) !== null && _d !== void 0 ? _d : (options.priority = false);
92
- logger.logMethodArgs('subscribe', { signalId, options });
88
+ (_e = logger.logMethodArgs) === null || _e === void 0 ? void 0 : _e.call(logger, 'subscribe', { signalId, options });
93
89
  const signal = getSignalObject(signalId);
94
90
  const listener = {
95
91
  id: ++_lastListenerAutoId,
@@ -98,8 +94,8 @@ export const subscribe = (signalId, listenerCallback, options = {}) => {
98
94
  disabled: options.disabled,
99
95
  callback: listenerCallback,
100
96
  };
101
- const callbackCall = signal.detail !== undefined && options.receivePrevious !== 'No';
102
- if (callbackCall) {
97
+ const execCallback = signal.detail !== undefined && options.receivePrevious !== 'No' && options.disabled !== true;
98
+ if (execCallback) {
103
99
  // Run callback for old dispatch signal
104
100
  const callback = () => {
105
101
  try {
@@ -120,7 +116,7 @@ export const subscribe = (signalId, listenerCallback, options = {}) => {
120
116
  }
121
117
  }
122
118
  // if once then must remove listener after fist callback called! then why push it to listenerList?!
123
- if (!(callbackCall && options.once)) {
119
+ if (!(execCallback && options.once)) {
124
120
  if (options.priority === true) {
125
121
  signal.listenerList.unshift(listener);
126
122
  }
@@ -145,7 +141,8 @@ export const subscribe = (signalId, listenerCallback, options = {}) => {
145
141
  * ```
146
142
  */
147
143
  export const unsubscribe = (listener) => {
148
- logger.logMethodArgs('unsubscribe', listener);
144
+ var _a;
145
+ (_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'unsubscribe', listener);
149
146
  const signal = getSignalObject(listener.signalId);
150
147
  const listenerIndex = signal.listenerList.findIndex((_listener) => _listener.id === listener.id);
151
148
  if (listenerIndex !== -1) {
@@ -162,7 +159,8 @@ export const unsubscribe = (listener) => {
162
159
  * ```
163
160
  */
164
161
  export const removeAllListeners = (signalId) => {
165
- logger.logMethodArgs('removeAllListeners', signalId);
162
+ var _a;
163
+ (_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'removeAllListeners', signalId);
166
164
  const signal = getSignalObject(signalId);
167
165
  if (signal.listenerList.length === 0)
168
166
  return;
@@ -181,24 +179,31 @@ export const removeAllListeners = (signalId) => {
181
179
  * ```
182
180
  */
183
181
  export const dispatch = (signalId, detail, options = {}) => {
184
- var _a;
182
+ var _a, _b;
185
183
  (_a = options.debounce) !== null && _a !== void 0 ? _a : (options.debounce = 'AnimationFrame');
186
- logger.logMethodArgs('dispatch', { signalId, detail, options });
184
+ (_b = logger.logMethodArgs) === null || _b === void 0 ? void 0 : _b.call(logger, 'dispatch', { signalId, detail, options });
187
185
  const signal = getSignalObject(signalId);
188
186
  // set detail before check signal.debounced for act like throttle (call listeners with last dispatch detail).
189
187
  signal.detail = detail;
190
188
  if (signal.disabled)
191
189
  return; // signal is disabled.
192
- // Simple debounce noise filtering
193
- if (options.debounce !== 'No' && signal.debounced === true)
194
- return; // last dispatch in progress.
195
190
  if (options.debounce === 'No') {
196
- return _callListeners(signal);
191
+ return _callListeners(signal, detail);
192
+ }
193
+ // else
194
+ if (options.debounce === 'NextCycle') {
195
+ setTimeout(_callListeners, 0, signal, detail);
196
+ return;
197
+ }
198
+ // else
199
+ if (signal.debounced === true) {
200
+ return; // last dispatch in progress.
197
201
  }
198
202
  // else
199
203
  signal.debounced = true;
200
204
  const callListeners = () => {
201
- _callListeners(signal);
205
+ var _a;
206
+ _callListeners(signal, (_a = signal.detail) !== null && _a !== void 0 ? _a : detail);
202
207
  signal.debounced = false;
203
208
  };
204
209
  options.debounce === 'AnimationFrame'
@@ -233,7 +238,8 @@ export const getDetail = (signalId) => {
233
238
  */
234
239
  export const untilNext = (signalId) => {
235
240
  return new Promise((resolve) => {
236
- logger.logMethodArgs('untilNext', signalId);
241
+ var _a;
242
+ (_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'untilNext', signalId);
237
243
  subscribe(signalId, resolve, {
238
244
  once: true,
239
245
  priority: true,
@@ -252,10 +258,10 @@ export const untilNext = (signalId) => {
252
258
  * ```
253
259
  */
254
260
  export const setContextProvider = (signalId, signalProvider, options = {}) => {
255
- var _a, _b;
261
+ var _a, _b, _c;
256
262
  (_a = options.debounce) !== null && _a !== void 0 ? _a : (options.debounce = 'AnimationFrame');
257
263
  (_b = options.receivePrevious) !== null && _b !== void 0 ? _b : (options.receivePrevious = 'AnimationFrame');
258
- logger.logMethodArgs('setContextProvider', { signalId, options });
264
+ (_c = logger.logMethodArgs) === null || _c === void 0 ? void 0 : _c.call(logger, 'setContextProvider', { signalId, options });
259
265
  const requestSignalId = 'request-' + signalId;
260
266
  removeAllListeners(requestSignalId);
261
267
  subscribe(requestSignalId, async (argumentObject) => {
@@ -284,12 +290,12 @@ export const setContextProvider = (signalId, signalProvider, options = {}) => {
284
290
  * ```
285
291
  */
286
292
  export const defineCommand = (signalId, signalProvider, options = {}) => {
287
- var _a;
293
+ var _a, _b;
288
294
  (_a = options.debounce) !== null && _a !== void 0 ? _a : (options.debounce = 'AnimationFrame');
289
- logger.logMethodArgs('defineCommand', { commandId: signalId, options });
295
+ (_b = logger.logMethodArgs) === null || _b === void 0 ? void 0 : _b.call(logger, 'defineCommand', { commandId: signalId, options });
290
296
  const requestSignalId = 'request-' + signalId;
291
297
  removeAllListeners(requestSignalId);
292
- subscribe(requestSignalId, async (argumentObject) => {
298
+ return subscribe(requestSignalId, async (argumentObject) => {
293
299
  clearDetail(requestSignalId); // clean argumentObject from memory
294
300
  if (argumentObject._callbackSignalId == null) {
295
301
  signalProvider(argumentObject);
@@ -311,8 +317,9 @@ export const defineCommand = (signalId, signalProvider, options = {}) => {
311
317
  * ```
312
318
  */
313
319
  export const requestContext = (contextId, requestParam, options = {}) => {
314
- logger.logMethodArgs('requestContext', { contextId, requestParam });
315
- return dispatch(contextId, requestParam, options);
320
+ var _a;
321
+ (_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'requestContext', { contextId, requestParam });
322
+ return dispatch(`request-${contextId}`, requestParam, options);
316
323
  };
317
324
  /**
318
325
  * Dispatch request command signal with commandArgument as detail.
@@ -324,7 +331,8 @@ export const requestContext = (contextId, requestParam, options = {}) => {
324
331
  * ```
325
332
  */
326
333
  export const requestCommand = (commandId, commandArgument) => {
327
- logger.logMethodArgs('requestCommand', { commandId, commandArgument });
334
+ var _a;
335
+ (_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'requestCommand', { commandId, commandArgument });
328
336
  dispatch(`request-${commandId}`, commandArgument, { debounce: 'No' });
329
337
  };
330
338
  /**
@@ -339,14 +347,15 @@ export const requestCommand = (commandId, commandArgument) => {
339
347
  * ```
340
348
  */
341
349
  export const requestCommandWithResponse = async (commandId, commandArgument) => {
342
- logger.logMethodArgs('requestCommand', { commandId, commandArgument });
350
+ var _a;
351
+ (_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'requestCommand', { commandId, commandArgument });
343
352
  const _requestSignalId = `request-${commandId}`;
344
353
  const _callbackSignalId = `callback-${commandId}-${++_lastListenerAutoId}`;
345
354
  const untilCallback = untilNext(_callbackSignalId);
346
355
  dispatch(_requestSignalId, {
347
356
  ...commandArgument,
348
357
  _callbackSignalId,
349
- }, { debounce: 'No' });
358
+ }, { debounce: 'NextCycle' });
350
359
  const response = await untilCallback;
351
360
  destroySignal(_callbackSignalId);
352
361
  return response;
@@ -363,7 +372,8 @@ export const requestCommandWithResponse = async (commandId, commandArgument) =>
363
372
  * ```
364
373
  */
365
374
  export const clearDetail = (signalId) => {
366
- logger.logMethodArgs('expire', signalId);
375
+ var _a;
376
+ (_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'expire', signalId);
367
377
  const signal = getSignalObject(signalId);
368
378
  delete signal.detail;
369
379
  };
@@ -379,7 +389,8 @@ export const clearDetail = (signalId) => {
379
389
  * ```
380
390
  */
381
391
  export const destroySignal = (signalId) => {
382
- logger.logMethodArgs('destroySignal', signalId);
392
+ var _a;
393
+ (_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'destroySignal', signalId);
383
394
  const signal = _signalStorage[signalId];
384
395
  if (signal == null)
385
396
  return;
package/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","sourceRoot":"","sources":["src/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAe1D,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC;IAC/B,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,gBAAgB;CAC1B,CAAC,CAAC;AAEH;;GAEG;AACH,IAAI,mBAAmB,GAAG,CAAC,CAAC;AAE5B,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B;;GAEG;AACH,MAAM,cAAc,GAAkB,EAAE,CAAC;AAEzC,MAAM,CAAC,MAAM,MAAM,GAAG,YAAY,CAAC,eAAe,CAAC,CA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E,IAAI,EAAC,CACnB,CAAC;IAEF,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC;IACrC,aAAa,CAAC,iBAAiB,CAAC,CAAC;IACjC,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,QAAgB,EAAQ,EAAE;IACpD,MAAM,CAAC,aAAa,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAAgB,EAAQ,EAAE;IACtD,MAAM,CAAC,aAAa,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IACxC,IAAI,MAAM,IAAI,IAAI;QAAE,OAAO;IAC3B,MAAM,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/B,OAAO,cAAc,CAAC,QAAQ,CAAC,CAAC;AAClC,CAAC,CAAC","sourcesContent":["import {createLogger, globalAlwatr} from '@alwatr/logger';\n\nimport type {\n DispatchOptions,\n ListenerFunction,\n ListenerObject,\n SubscribeOptions,\n SignalObject,\n ProviderFunction,\n ProviderOptions,\n SignalStorage,\n ListenerSpec,\n} from './type.js';\nimport type {Stringifyable, StringifyableRecord} from '@alwatr/type';\n\nglobalAlwatr.registeredList.push({\n name: '@alwatr/signal',\n version: _ALWATR_VERSION_,\n});\n\n/**\n * Listener `id`\n */\nlet _lastListenerAutoId = 0;\n\nconst debounceTimeout = 5;\n\n/**\n * Signal stack database.\n */\nconst _signalStorage: SignalStorage = {};\n\nexport const logger = createLogger('alwatr/signal');\n\n/**\n * Get signal object by id, If not available, it will create a new signal with default options.\n *\n * Don't use it directly.\n *\n * Example:\n *\n * ```ts\n * const signal = getSignalObject<ContentType>('content-change');\n * signal.disabled = true;\n * ```\n */\nexport const getSignalObject = <T extends Stringifyable>(id: string): SignalObject<T> => {\n let signal = _signalStorage[id] as SignalObject<T> | undefined;\n if (signal == null) {\n signal = _signalStorage[id] = {\n id,\n disabled: false,\n debounced: false,\n listenerList: [],\n };\n }\n return signal;\n};\n\n/**\n * Call all listeners callback of special signal.\n *\n * Used inside dispatch, Don't use it directly.\n */\nexport const _callListeners = <T extends Stringifyable>(signal: SignalObject<T>): void => {\n logger.logMethodArgs('_callListeners', {signalId: signal.id, signalDetail: signal.detail});\n\n if (signal.detail === undefined) {\n logger.accident('_callListeners', 'no_signal_detail', 'signal must have a detail', {\n signalId: signal.id,\n });\n return;\n }\n\n const removeList: Array<ListenerObject<T>> = [];\n\n for (const listener of signal.listenerList) {\n if (listener.disabled) continue;\n if (listener.once) removeList.push(listener);\n try {\n const ret = listener.callback(signal.detail);\n if (ret instanceof Promise) {\n ret.catch((err) =>\n logger.error('_callListeners', 'call_listener_failed', err, {\n signalId: signal.id,\n }),\n );\n }\n }\n catch (err) {\n logger.error('_callListeners', 'call_listener_failed', err, {\n signalId: signal.id,\n });\n }\n }\n\n removeList.forEach((listener) => unsubscribe(listener));\n};\n\n/**\n * Subscribe new signal listener to a signal, work like addEventListener.\n *\n * Example:\n *\n * ```ts\n * const listener = subscribe<ContentType>('content-change', (content) => console.log(content));\n * // ...\n * unsubscribe(listener);\n * ```\n */\nexport const subscribe = <T extends Stringifyable>(\n signalId: string,\n listenerCallback: ListenerFunction<T>,\n options: Partial<SubscribeOptions> = {},\n): ListenerSpec => {\n options.once ??= false;\n options.disabled ??= false;\n options.receivePrevious ??= 'AnimationFrame';\n options.priority ??= false;\n\n logger.logMethodArgs('subscribe', {signalId, options});\n\n const signal = getSignalObject<T>(signalId);\n\n const listener: ListenerObject<T> = {\n id: ++_lastListenerAutoId,\n signalId: signal.id,\n once: options.once,\n disabled: options.disabled,\n callback: listenerCallback,\n };\n\n const callbackCall = signal.detail !== undefined && options.receivePrevious !== 'No';\n if (callbackCall) {\n // Run callback for old dispatch signal\n\n const callback = (): void => {\n try {\n if (signal.detail !== undefined) listenerCallback(signal.detail);\n }\n catch (err) {\n logger.error('subscribe', 'call_signal_callback_failed', err, {\n signalId: signal.id,\n });\n }\n };\n\n if (options.receivePrevious === 'AnimationFrame') {\n requestAnimationFrame(callback);\n }\n else {\n setTimeout(callback, options.receivePrevious === 'NextCycle' ? 0 : debounceTimeout);\n }\n }\n\n // if once then must remove listener after fist callback called! then why push it to listenerList?!\n if (!(callbackCall && options.once)) {\n if (options.priority === true) {\n signal.listenerList.unshift(listener);\n }\n else {\n signal.listenerList.push(listener);\n }\n }\n\n return {\n id: listener.id,\n signalId: listener.signalId,\n };\n};\n\n/**\n * Unsubscribe listener from signal, work like removeEventListener.\n *\n * Example:\n *\n * ```ts\n * const listener = subscribe<ContentType>('content-change', (content) => console.log(content));\n * // ...\n * unsubscribe(listener);\n * ```\n */\nexport const unsubscribe = (listener: ListenerSpec): void => {\n logger.logMethodArgs('unsubscribe', listener);\n const signal = getSignalObject(listener.signalId);\n const listenerIndex = signal.listenerList.findIndex((_listener) => _listener.id === listener.id);\n if (listenerIndex !== -1) {\n void signal.listenerList.splice(listenerIndex, 1);\n }\n};\n\n/**\n * Unsubscribe all listener from a signal, clear all listeners.\n *\n * Example:\n *\n * ```ts\n * removeAllListeners('content-change');\n * ```\n */\nexport const removeAllListeners = (signalId: string): void => {\n logger.logMethodArgs('removeAllListeners', signalId);\n const signal = getSignalObject(signalId);\n if (signal.listenerList.length === 0) return;\n signal.listenerList.length = 0;\n signal.listenerList = [];\n};\n\n/**\n * Dispatch (send) signal to all listeners.\n *\n * Signal detail changed immediately without any debounce.\n *\n * Example:\n *\n * ```ts\n * dispatch<ContentType>('content-change', newContent);\n * ```\n */\nexport const dispatch = <T extends Stringifyable>(\n signalId: string,\n detail: T,\n options: Partial<DispatchOptions> = {},\n): void => {\n options.debounce ??= 'AnimationFrame';\n\n logger.logMethodArgs('dispatch', {signalId, detail, options});\n\n const signal = getSignalObject<T>(signalId);\n\n // set detail before check signal.debounced for act like throttle (call listeners with last dispatch detail).\n signal.detail = detail;\n\n if (signal.disabled) return; // signal is disabled.\n\n // Simple debounce noise filtering\n if (options.debounce !== 'No' && signal.debounced === true) return; // last dispatch in progress.\n\n if (options.debounce === 'No') {\n return _callListeners(signal);\n }\n // else\n signal.debounced = true;\n const callListeners = (): void => {\n _callListeners(signal);\n signal.debounced = false;\n };\n options.debounce === 'AnimationFrame'\n ? requestAnimationFrame(callListeners)\n : setTimeout(callListeners, debounceTimeout);\n};\n\n/**\n * Get current signal detail/value.\n *\n * Return undefined if signal not dispatched before or expired.\n *\n * Example:\n *\n * ```ts\n * const currentContent = getDetail<ContentType>('content-change');\n * if (currentContent === undefined) {\n * // signal not dispatched yet\n * }\n * ```\n */\nexport const getDetail = <T extends Stringifyable>(signalId: string): T | undefined => {\n return getSignalObject<T>(signalId).detail;\n};\n\n/**\n * Get the detail/value of the next received signal.\n *\n * Example:\n *\n * ```ts\n * const newContent = await untilNext<ContentType>('content-change');\n * ```\n */\nexport const untilNext = <T extends Stringifyable>(signalId: string): Promise<T> => {\n return new Promise((resolve) => {\n logger.logMethodArgs('untilNext', signalId);\n subscribe<T>(signalId, resolve, {\n once: true,\n priority: true,\n receivePrevious: 'No',\n });\n });\n};\n\n/**\n * Defines the provider of the context signal that will be called when the context requested.\n * Subscribe to `request-signalId`.\n *\n * Example:\n *\n * ```ts\n * setContextProvider('content-change', async (requestParam) => await fetchNewContent(requestParam));\n * ```\n */\nexport const setContextProvider = <TContext extends Stringifyable, TRquest extends Stringifyable>(\n signalId: string,\n signalProvider: ProviderFunction<TRquest, TContext | void>,\n options: Partial<ProviderOptions> = {},\n): void => {\n options.debounce ??= 'AnimationFrame';\n options.receivePrevious ??= 'AnimationFrame';\n logger.logMethodArgs('setContextProvider', {signalId, options});\n const requestSignalId = 'request-' + signalId;\n removeAllListeners(requestSignalId);\n subscribe<TRquest>(\n requestSignalId,\n async (argumentObject): Promise<void> => {\n const signalDetail = await signalProvider(argumentObject);\n if (signalDetail !== undefined) {\n dispatch<TContext>(signalId, signalDetail, {debounce: options.debounce});\n }\n },\n {\n receivePrevious: options.receivePrevious,\n },\n );\n};\n\n/**\n * Defines the command and dispatch returned value.\n *\n * Subscribe commandFunction to request-command-signal and dispatch callback-signal with commandFunction return value.\n *\n * Example:\n *\n * ```ts\n * defineCommand<TArgument, TReturn>(\n * 'show-prompt',\n * async (argumentObject) => {\n * return await showPrompt(argumentObject);\n * },\n * );\n * ```\n */\nexport const defineCommand = <TArgument extends StringifyableRecord, TReturn extends Stringifyable>(\n signalId: string,\n signalProvider: ProviderFunction<TArgument & {_callbackSignalId?: string}, TReturn>,\n options: Partial<Pick<ProviderOptions, 'debounce'>> = {},\n): void => {\n options.debounce ??= 'AnimationFrame';\n logger.logMethodArgs('defineCommand', {commandId: signalId, options});\n const requestSignalId = 'request-' + signalId;\n removeAllListeners(requestSignalId);\n subscribe<TArgument & {_callbackSignalId?: string}>(\n requestSignalId,\n async (argumentObject) => {\n clearDetail(requestSignalId); // clean argumentObject from memory\n if (argumentObject._callbackSignalId == null) {\n signalProvider(argumentObject);\n }\n else {\n // prettier-ignore\n dispatch<TReturn>(\n argumentObject._callbackSignalId,\n await signalProvider(argumentObject),\n {debounce: options.debounce},\n );\n }\n },\n {receivePrevious: 'NextCycle'},\n );\n};\n\n/**\n * Dispatch request context signal with requestParam as detail.\n *\n * Example:\n *\n * ```ts\n * requestContext<RequestParamType>('content-change', {foo: 'bar'});\n * const newContent = await untilNext<ContentType>('content-change');\n * ```\n */\nexport const requestContext = <TRequest extends Stringifyable>(\n contextId: string,\n requestParam: TRequest,\n options: Partial<DispatchOptions> = {},\n): void => {\n logger.logMethodArgs('requestContext', {contextId, requestParam});\n return dispatch<TRequest>(contextId, requestParam, options);\n};\n\n/**\n * Dispatch request command signal with commandArgument as detail.\n *\n * Example:\n *\n * ```ts\n * requestCommand<ArgumentType>('show-dialog', {foo: 'bar'});\n * ```\n */\nexport const requestCommand = <TArgument extends StringifyableRecord>(\n commandId: string,\n commandArgument: TArgument,\n): void => {\n logger.logMethodArgs('requestCommand', {commandId, commandArgument});\n dispatch<TArgument>(`request-${commandId}`, commandArgument, {debounce: 'No'});\n};\n\n/**\n * Dispatch request command signal with commandArgument as detail and return untilNext of callback signal.\n *\n * Request command and wait for answer.\n *\n * Example:\n *\n * ```ts\n * const response = await requestCommandWithResponse<ArgumentType, ReturnType>('show-dialog', {foo: 'bar'});\n * ```\n */\nexport const requestCommandWithResponse = async <\n TArgument extends StringifyableRecord,\n TReturn extends Stringifyable\n>(\n commandId: string,\n commandArgument: TArgument,\n): Promise<TReturn> => {\n logger.logMethodArgs('requestCommand', {commandId, commandArgument});\n\n const _requestSignalId = `request-${commandId}`;\n const _callbackSignalId = `callback-${commandId}-${++_lastListenerAutoId}`;\n const untilCallback = untilNext<TReturn>(_callbackSignalId);\n\n dispatch<TArgument & {_callbackSignalId: string}>(\n _requestSignalId,\n {\n ...commandArgument,\n _callbackSignalId,\n },\n {debounce: 'No'},\n );\n\n const response = await untilCallback;\n destroySignal(_callbackSignalId);\n return response;\n};\n\n/**\n * Clear current signal detail without dispatch new signal.\n *\n * new subscriber options.receivePrevious not work until new signal\n *\n * Example:\n *\n * ```ts\n * clearDetail('product-list');\n * ```\n */\nexport const clearDetail = (signalId: string): void => {\n logger.logMethodArgs('expire', signalId);\n const signal = getSignalObject(signalId);\n delete signal.detail;\n};\n\n/**\n * Delete signal object with detail and listeners and options.\n *\n * new subscriber options.receivePrevious not work until new signal\n *\n * Example:\n *\n * ```ts\n * destroySignal('product-list');\n * ```\n */\nexport const destroySignal = (signalId: string): void => {\n logger.logMethodArgs('destroySignal', signalId);\n const signal = _signalStorage[signalId];\n if (signal == null) return;\n signal.listenerList.length = 0;\n delete _signalStorage[signalId];\n};\n"]}
1
+ {"version":3,"file":"core.js","sourceR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I;QAAE,OAAO;IAC3B,MAAM,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/B,OAAO,cAAc,CAAC,QAAQ,CAAC,CAAC;AAClC,CAAC,CAAC","sourcesContent":["import {createLogger, globalAlwatr} from '@alwatr/logger';\nimport {requestAnimationFrame} from '@alwatr/util';\n\nimport type {\n DispatchOptions,\n ListenerFunction,\n ListenerObject,\n SubscribeOptions,\n SignalObject,\n ProviderFunction,\n ProviderOptions,\n SignalStorage,\n ListenerSpec,\n} from './type.js';\nimport type {Stringifyable, StringifyableRecord} from '@alwatr/type';\n\nglobalAlwatr.registeredList.push({\n name: '@alwatr/signal',\n version: _ALWATR_VERSION_,\n});\n\n/**\n * Listener `id`\n */\nlet _lastListenerAutoId = 0;\n\nconst debounceTimeout = 5;\n\n/**\n * Signal stack database.\n */\nconst _signalStorage: SignalStorage = {};\n\nexport const logger = createLogger('alwatr/signal');\n\n/**\n * Get signal object by id, If not available, it will create a new signal with default options.\n *\n * Don't use it directly.\n *\n * Example:\n *\n * ```ts\n * const signal = getSignalObject<ContentType>('content-change');\n * signal.disabled = true;\n * ```\n */\nexport const getSignalObject = <T extends Stringifyable>(id: string): SignalObject<T> => {\n let signal = _signalStorage[id] as SignalObject<T> | undefined;\n if (signal == null) {\n signal = _signalStorage[id] = {\n id,\n disabled: false,\n debounced: false,\n listenerList: [],\n };\n }\n return signal;\n};\n\n/**\n * Call all listeners callback of special signal.\n *\n * Used inside dispatch, Don't use it directly.\n */\nexport const _callListeners = <T extends Stringifyable>(signal: SignalObject<T>, detail: T): void => {\n logger.logMethodArgs?.('_callListeners', {signalId: signal.id, signalDetail: detail});\n\n const removeList: Array<ListenerObject<T>> = [];\n\n for (const listener of signal.listenerList) {\n if (listener.disabled) continue;\n if (listener.once) removeList.push(listener);\n try {\n const ret = listener.callback(detail);\n if (ret instanceof Promise) {\n ret.catch((err) =>\n logger.error('_callListeners', 'call_listener_failed', err, {\n signalId: signal.id,\n }),\n );\n }\n }\n catch (err) {\n logger.error('_callListeners', 'call_listener_failed', err, {\n signalId: signal.id,\n });\n }\n }\n\n removeList.forEach((listener) => unsubscribe(listener));\n};\n\n/**\n * Subscribe new signal listener to a signal, work like addEventListener.\n *\n * Example:\n *\n * ```ts\n * const listener = subscribe<ContentType>('content-change', (content) => console.log(content));\n * // ...\n * unsubscribe(listener);\n * ```\n */\nexport const subscribe = <T extends Stringifyable>(\n signalId: string,\n listenerCallback: ListenerFunction<T>,\n options: Partial<SubscribeOptions> = {},\n): ListenerSpec => {\n options.once ??= false;\n options.disabled ??= false;\n options.receivePrevious ??= 'NextCycle';\n options.priority ??= false;\n\n logger.logMethodArgs?.('subscribe', {signalId, options});\n\n const signal = getSignalObject<T>(signalId);\n\n const listener: ListenerObject<T> = {\n id: ++_lastListenerAutoId,\n signalId: signal.id,\n once: options.once,\n disabled: options.disabled,\n callback: listenerCallback,\n };\n\n const execCallback = signal.detail !== undefined && options.receivePrevious !== 'No' && options.disabled !== true;\n if (execCallback) {\n // Run callback for old dispatch signal\n\n const callback = (): void => {\n try {\n if (signal.detail !== undefined) listenerCallback(signal.detail);\n }\n catch (err) {\n logger.error('subscribe', 'call_signal_callback_failed', err, {\n signalId: signal.id,\n });\n }\n };\n\n if (options.receivePrevious === 'AnimationFrame') {\n requestAnimationFrame(callback);\n }\n else {\n setTimeout(callback, options.receivePrevious === 'NextCycle' ? 0 : debounceTimeout);\n }\n }\n\n // if once then must remove listener after fist callback called! then why push it to listenerList?!\n if (!(execCallback && options.once)) {\n if (options.priority === true) {\n signal.listenerList.unshift(listener);\n }\n else {\n signal.listenerList.push(listener);\n }\n }\n\n return {\n id: listener.id,\n signalId: listener.signalId,\n };\n};\n\n/**\n * Unsubscribe listener from signal, work like removeEventListener.\n *\n * Example:\n *\n * ```ts\n * const listener = subscribe<ContentType>('content-change', (content) => console.log(content));\n * // ...\n * unsubscribe(listener);\n * ```\n */\nexport const unsubscribe = (listener: ListenerSpec): void => {\n logger.logMethodArgs?.('unsubscribe', listener);\n const signal = getSignalObject(listener.signalId);\n const listenerIndex = signal.listenerList.findIndex((_listener) => _listener.id === listener.id);\n if (listenerIndex !== -1) {\n void signal.listenerList.splice(listenerIndex, 1);\n }\n};\n\n/**\n * Unsubscribe all listener from a signal, clear all listeners.\n *\n * Example:\n *\n * ```ts\n * removeAllListeners('content-change');\n * ```\n */\nexport const removeAllListeners = (signalId: string): void => {\n logger.logMethodArgs?.('removeAllListeners', signalId);\n const signal = getSignalObject(signalId);\n if (signal.listenerList.length === 0) return;\n signal.listenerList.length = 0;\n signal.listenerList = [];\n};\n\n/**\n * Dispatch (send) signal to all listeners.\n *\n * Signal detail changed immediately without any debounce.\n *\n * Example:\n *\n * ```ts\n * dispatch<ContentType>('content-change', newContent);\n * ```\n */\nexport const dispatch = <T extends Stringifyable>(\n signalId: string,\n detail: T,\n options: Partial<DispatchOptions> = {},\n): void => {\n options.debounce ??= 'AnimationFrame';\n\n logger.logMethodArgs?.('dispatch', {signalId, detail, options});\n\n const signal = getSignalObject<T>(signalId);\n\n // set detail before check signal.debounced for act like throttle (call listeners with last dispatch detail).\n signal.detail = detail;\n\n if (signal.disabled) return; // signal is disabled.\n\n if (options.debounce === 'No') {\n return _callListeners(signal, detail);\n }\n\n // else\n if (options.debounce === 'NextCycle') {\n setTimeout(_callListeners, 0, signal, detail);\n return;\n }\n\n // else\n if (signal.debounced === true) {\n return; // last dispatch in progress.\n }\n\n // else\n signal.debounced = true;\n const callListeners = (): void => {\n _callListeners(signal, signal.detail ?? detail);\n signal.debounced = false;\n };\n options.debounce === 'AnimationFrame'\n ? requestAnimationFrame(callListeners)\n : setTimeout(callListeners, debounceTimeout);\n};\n\n/**\n * Get current signal detail/value.\n *\n * Return undefined if signal not dispatched before or expired.\n *\n * Example:\n *\n * ```ts\n * const currentContent = getDetail<ContentType>('content-change');\n * if (currentContent === undefined) {\n * // signal not dispatched yet\n * }\n * ```\n */\nexport const getDetail = <T extends Stringifyable>(signalId: string): T | undefined => {\n return getSignalObject<T>(signalId).detail;\n};\n\n/**\n * Get the detail/value of the next received signal.\n *\n * Example:\n *\n * ```ts\n * const newContent = await untilNext<ContentType>('content-change');\n * ```\n */\nexport const untilNext = <T extends Stringifyable>(signalId: string): Promise<T> => {\n return new Promise((resolve) => {\n logger.logMethodArgs?.('untilNext', signalId);\n subscribe<T>(signalId, resolve, {\n once: true,\n priority: true,\n receivePrevious: 'No',\n });\n });\n};\n\n/**\n * Defines the provider of the context signal that will be called when the context requested.\n * Subscribe to `request-signalId`.\n *\n * Example:\n *\n * ```ts\n * setContextProvider('content-change', async (requestParam) => await fetchNewContent(requestParam));\n * ```\n */\nexport const setContextProvider = <TContext extends Stringifyable, TRquest extends Stringifyable = null>(\n signalId: string,\n signalProvider: ProviderFunction<TRquest, TContext | void>,\n options: Partial<ProviderOptions> = {},\n): void => {\n options.debounce ??= 'AnimationFrame';\n options.receivePrevious ??= 'AnimationFrame';\n logger.logMethodArgs?.('setContextProvider', {signalId, options});\n const requestSignalId = 'request-' + signalId;\n removeAllListeners(requestSignalId);\n subscribe<TRquest>(\n requestSignalId,\n async (argumentObject): Promise<void> => {\n const signalDetail = await signalProvider(argumentObject);\n if (signalDetail !== undefined) {\n dispatch<TContext>(signalId, signalDetail, {debounce: options.debounce});\n }\n },\n {\n receivePrevious: options.receivePrevious,\n },\n );\n};\n\n/**\n * Defines the command and dispatch returned value.\n *\n * Subscribe commandFunction to request-command-signal and dispatch callback-signal with commandFunction return value.\n *\n * Example:\n *\n * ```ts\n * defineCommand<TArgument, TReturn>(\n * 'show-prompt',\n * async (argumentObject) => {\n * return await showPrompt(argumentObject);\n * },\n * );\n * ```\n */\nexport const defineCommand = <TArgument extends StringifyableRecord, TReturn extends Stringifyable>(\n signalId: string,\n signalProvider: ProviderFunction<TArgument & {_callbackSignalId?: string}, TReturn>,\n options: Partial<Pick<ProviderOptions, 'debounce'>> = {},\n): ListenerSpec => {\n options.debounce ??= 'AnimationFrame';\n logger.logMethodArgs?.('defineCommand', {commandId: signalId, options});\n const requestSignalId = 'request-' + signalId;\n removeAllListeners(requestSignalId);\n return subscribe<TArgument & {_callbackSignalId?: string}>(\n requestSignalId,\n async (argumentObject) => {\n clearDetail(requestSignalId); // clean argumentObject from memory\n if (argumentObject._callbackSignalId == null) {\n signalProvider(argumentObject);\n }\n else {\n // prettier-ignore\n dispatch<TReturn>(\n argumentObject._callbackSignalId,\n await signalProvider(argumentObject),\n {debounce: options.debounce},\n );\n }\n },\n {receivePrevious: 'NextCycle'},\n );\n};\n\n/**\n * Dispatch request context signal with requestParam as detail.\n *\n * Example:\n *\n * ```ts\n * requestContext<RequestParamType>('content-change', {foo: 'bar'});\n * const newContent = await untilNext<ContentType>('content-change');\n * ```\n */\nexport const requestContext = <TRequest extends Stringifyable>(\n contextId: string,\n requestParam: TRequest,\n options: Partial<DispatchOptions> = {},\n): void => {\n logger.logMethodArgs?.('requestContext', {contextId, requestParam});\n return dispatch<TRequest>(`request-${contextId}`, requestParam, options);\n};\n\n/**\n * Dispatch request command signal with commandArgument as detail.\n *\n * Example:\n *\n * ```ts\n * requestCommand<ArgumentType>('show-dialog', {foo: 'bar'});\n * ```\n */\nexport const requestCommand = <TArgument extends StringifyableRecord>(\n commandId: string,\n commandArgument: TArgument,\n): void => {\n logger.logMethodArgs?.('requestCommand', {commandId, commandArgument});\n dispatch<TArgument>(`request-${commandId}`, commandArgument, {debounce: 'No'});\n};\n\n/**\n * Dispatch request command signal with commandArgument as detail and return untilNext of callback signal.\n *\n * Request command and wait for answer.\n *\n * Example:\n *\n * ```ts\n * const response = await requestCommandWithResponse<ArgumentType, ReturnType>('show-dialog', {foo: 'bar'});\n * ```\n */\nexport const requestCommandWithResponse = async <\n TArgument extends StringifyableRecord,\n TReturn extends Stringifyable\n>(\n commandId: string,\n commandArgument: TArgument,\n): Promise<TReturn> => {\n logger.logMethodArgs?.('requestCommand', {commandId, commandArgument});\n\n const _requestSignalId = `request-${commandId}`;\n const _callbackSignalId = `callback-${commandId}-${++_lastListenerAutoId}`;\n const untilCallback = untilNext<TReturn>(_callbackSignalId);\n\n dispatch<TArgument & {_callbackSignalId: string}>(\n _requestSignalId,\n {\n ...commandArgument,\n _callbackSignalId,\n },\n {debounce: 'NextCycle'},\n );\n\n const response = await untilCallback;\n destroySignal(_callbackSignalId);\n return response;\n};\n\n/**\n * Clear current signal detail without dispatch new signal.\n *\n * new subscriber options.receivePrevious not work until new signal\n *\n * Example:\n *\n * ```ts\n * clearDetail('product-list');\n * ```\n */\nexport const clearDetail = (signalId: string): void => {\n logger.logMethodArgs?.('expire', signalId);\n const signal = getSignalObject(signalId);\n delete signal.detail;\n};\n\n/**\n * Delete signal object with detail and listeners and options.\n *\n * new subscriber options.receivePrevious not work until new signal\n *\n * Example:\n *\n * ```ts\n * destroySignal('product-list');\n * ```\n */\nexport const destroySignal = (signalId: string): void => {\n logger.logMethodArgs?.('destroySignal', signalId);\n const signal = _signalStorage[signalId];\n if (signal == null) return;\n signal.listenerList.length = 0;\n delete _signalStorage[signalId];\n};\n"]}
package/index.d.ts CHANGED
@@ -6,5 +6,5 @@ export * from './event-listener.js';
6
6
  export * from './event-trigger.js';
7
7
  export * from './requestable-context-consumer.js';
8
8
  export * from './requestable-context-provider.js';
9
- export type { ListenerSpec } from './type.js';
9
+ export type { ListenerSpec, DebounceType, DispatchOptions } from './type.js';
10
10
  //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,YAAY,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,YAAY,EAAC,YAAY,EAAE,YAAY,EAAE,eAAe,EAAC,MAAM,WAAW,CAAC"}
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAGlD;;;;;;;EAOE","sourcesContent":["export * from './command-handler.js';\nexport * from './command-trigger.js';\nexport * from './context-consumer.js';\nexport * from './context-provider.js';\nexport * from './event-listener.js';\nexport * from './event-trigger.js';\nexport * from './requestable-context-consumer.js';\nexport * from './requestable-context-provider.js';\nexport type {ListenerSpec} from './type.js';\n\n/*\nTODO:\n 1. change signal option like disable\n 2. Get signal value without undefined\n (Get signal value from last dispatched signal (if any) or wait for new signal received.)\n 3. dispatched bool\n 4. optional commandProvider debounce\n*/\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAGlD;;;;;;;EAOE","sourcesContent":["export * from './command-handler.js';\nexport * from './command-trigger.js';\nexport * from './context-consumer.js';\nexport * from './context-provider.js';\nexport * from './event-listener.js';\nexport * from './event-trigger.js';\nexport * from './requestable-context-consumer.js';\nexport * from './requestable-context-provider.js';\nexport type {ListenerSpec, DebounceType, DispatchOptions} from './type.js';\n\n/*\nTODO:\n 1. change signal option like disable\n 2. Get signal value without undefined\n (Get signal value from last dispatched signal (if any) or wait for new signal received.)\n 3. dispatched bool\n 4. optional commandProvider debounce\n*/\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alwatr/signal",
3
- "version": "0.29.0",
3
+ "version": "0.31.0",
4
4
  "description": "Elegant powerful event system for handle global signals and states written in tiny TypeScript module.",
5
5
  "keywords": [
6
6
  "signal",
@@ -29,8 +29,10 @@
29
29
  "url": "https://github.com/AliMD/alwatr/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@alwatr/logger": "^0.29.0",
32
+ "@alwatr/logger": "^0.31.0",
33
+ "@alwatr/type": "^0.31.0",
34
+ "@alwatr/util": "^0.31.0",
33
35
  "tslib": "^2.5.0"
34
36
  },
35
- "gitHead": "801487f183f8afd8cba25e0fec5d508c0b4fe809"
37
+ "gitHead": "896e64b58eed6e9048e870557ecf399d42705612"
36
38
  }
@@ -1,3 +1,4 @@
1
+ import { RequestableContext } from './type.js';
1
2
  import type { Stringifyable } from '@alwatr/type';
2
3
  /**
3
4
  * Requestable context consumer interface.
@@ -10,7 +11,7 @@ export declare const requestableContextConsumer: {
10
11
  *
11
12
  * ```ts
12
13
  * requestableContextConsumer.request<RequestParamType>('product-list', {foo: 'bar'});
13
- * const newProductList = await requestableContextConsumer.untilChange<ProductListType>('product-list');
14
+ * TODO: update me
14
15
  * ```
15
16
  */
16
17
  readonly request: <TRequest extends Stringifyable>(contextId: string, requestParam: TRequest, options?: Partial<import("./type.js").DispatchOptions>) => void;
@@ -23,7 +24,18 @@ export declare const requestableContextConsumer: {
23
24
  * const productListConsumer = requestableContextConsumer.bind<ProductListType>('product-list');
24
25
  * ```
25
26
  */
26
- readonly bind: <TContext extends Stringifyable, TRquest extends Stringifyable>(contextId: string) => {
27
+ readonly bind: <TContextContent extends Stringifyable, TRquest extends Stringifyable = null>(contextId: string) => {
28
+ /**
29
+ * Get context value.
30
+ *
31
+ * Example:
32
+ *
33
+ * ```ts
34
+ * const currentProductList = productListConsumer.getValue();
35
+ * TODO: update me
36
+ * ```
37
+ */
38
+ readonly getValue: () => RequestableContext<TContextContent>;
27
39
  /**
28
40
  * Send new context request to the provider.
29
41
  *
@@ -31,14 +43,13 @@ export declare const requestableContextConsumer: {
31
43
  *
32
44
  * ```ts
33
45
  * productListConsumer.request({foo: 'bar'});
34
- * const newProductList = await productListConsumer.untilChange();
46
+ * TODO: update me
35
47
  * ```
36
48
  */
37
49
  readonly request: (requestParam: TRquest, options?: Partial<import("./type.js").DispatchOptions> | undefined) => void;
38
50
  readonly id: string;
39
- readonly getValue: () => TContext | undefined;
40
- readonly untilChange: () => Promise<TContext>;
41
- readonly subscribe: (listenerCallback: import("./type.js").ListenerFunction<TContext>, options?: Partial<import("./type.js").SubscribeOptions> | undefined) => import("./type.js").ListenerSpec;
51
+ readonly untilChange: () => Promise<RequestableContext<TContextContent>>;
52
+ readonly subscribe: (listenerCallback: import("./type.js").ListenerFunction<RequestableContext<TContextContent>>, options?: Partial<import("./type.js").SubscribeOptions> | undefined) => import("./type.js").ListenerSpec;
42
53
  readonly unsubscribe: (listener: import("./type.js").ListenerSpec) => void;
43
54
  };
44
55
  readonly getValue: <T extends Stringifyable>(signalId: string) => T | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"requestable-context-consumer.d.ts","sourceRoot":"","sources":["src/requestable-context-consumer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAI,EAAC,aAAa,EAAiB,MAAM,cAAc,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,0BAA0B;IAGrC;;;;;;;;;OASG;;IAGH;;;;;;;;OAQG;8FAC8E,MAAM;QAGrF;;;;;;;;;WASG;;;;;;;;;;;;CAIG,CAAC"}
1
+ {"version":3,"file":"requestable-context-consumer.d.ts","sourceRoot":"","sources":["src/requestable-context-consumer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,kBAAkB,EAAC,MAAM,WAAW,CAAC;AAE7C,OAAO,KAAK,EAAC,aAAa,EAAiB,MAAM,cAAc,CAAC;AAEhE;;GAEG;AACH,eAAO,MAAM,0BAA0B;IAGrC;;;;;;;;;OASG;;IAGH;;;;;;;;OAQG;4GAC4F,MAAM;QAGnG;;;;;;;;;WASG;;QAIH;;;;;;;;;WASG;;;;;;;;;;;CAIG,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { contextConsumer } from './context-consumer.js';
2
- import { requestContext } from './core.js';
2
+ import { getDetail, requestContext } from './core.js';
3
3
  /**
4
4
  * Requestable context consumer interface.
5
5
  */
@@ -12,7 +12,7 @@ export const requestableContextConsumer = {
12
12
  *
13
13
  * ```ts
14
14
  * requestableContextConsumer.request<RequestParamType>('product-list', {foo: 'bar'});
15
- * const newProductList = await requestableContextConsumer.untilChange<ProductListType>('product-list');
15
+ * TODO: update me
16
16
  * ```
17
17
  */
18
18
  request: requestContext,
@@ -27,6 +27,17 @@ export const requestableContextConsumer = {
27
27
  */
28
28
  bind: (contextId) => ({
29
29
  ...contextConsumer.bind(contextId),
30
+ /**
31
+ * Get context value.
32
+ *
33
+ * Example:
34
+ *
35
+ * ```ts
36
+ * const currentProductList = productListConsumer.getValue();
37
+ * TODO: update me
38
+ * ```
39
+ */
40
+ getValue: () => { var _a; return (_a = getDetail(contextId)) !== null && _a !== void 0 ? _a : { state: 'initial' }; },
30
41
  /**
31
42
  * Send new context request to the provider.
32
43
  *
@@ -34,10 +45,10 @@ export const requestableContextConsumer = {
34
45
  *
35
46
  * ```ts
36
47
  * productListConsumer.request({foo: 'bar'});
37
- * const newProductList = await productListConsumer.untilChange();
48
+ * TODO: update me
38
49
  * ```
39
50
  */
40
- request: requestContext,
51
+ request: requestContext.bind(null, contextId),
41
52
  }),
42
53
  };
43
54
  //# sourceMappingURL=requestable-context-consumer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"requestable-context-consumer.js","sourceRoot":"","sources":["src/requestable-context-consumer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAC,cAAc,EAAC,MAAM,WAAW,CAAC;AAIzC;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,GAAG,eAAe;IAElB;;;;;;;;;OASG;IACH,OAAO,EAAE,cAAc;IAEvB;;;;;;;;OAQG;IACH,IAAI,EAAE,CAAgE,SAAiB,EAAE,EAAE,CAAA,CAAC;QAC1F,GAAG,eAAe,CAAC,IAAI,CAAW,SAAS,CAAC;QAE5C;;;;;;;;;WASG;QACH,OAAO,EAAE,cACuC;KACvC,CAAA;CACH,CAAC","sourcesContent":["import {contextConsumer} from './context-consumer.js';\nimport {requestContext} from './core.js';\n\nimport type{Stringifyable, OmitFirstParam} from '@alwatr/type';\n\n/**\n * Requestable context consumer interface.\n */\nexport const requestableContextConsumer = {\n ...contextConsumer,\n\n /**\n * Send new context request to the provider.\n *\n * Example:\n *\n * ```ts\n * requestableContextConsumer.request<RequestParamType>('product-list', {foo: 'bar'});\n * const newProductList = await requestableContextConsumer.untilChange<ProductListType>('product-list');\n * ```\n */\n request: requestContext,\n\n /**\n * Bind this interface to special context.\n *\n * Example:\n *\n * ```ts\n * const productListConsumer = requestableContextConsumer.bind<ProductListType>('product-list');\n * ```\n */\n bind: <TContext extends Stringifyable, TRquest extends Stringifyable>(contextId: string) =>({\n ...contextConsumer.bind<TContext>(contextId),\n\n /**\n * Send new context request to the provider.\n *\n * Example:\n *\n * ```ts\n * productListConsumer.request({foo: 'bar'});\n * const newProductList = await productListConsumer.untilChange();\n * ```\n */\n request: requestContext as\n OmitFirstParam<typeof requestContext<TRquest>>,\n } as const),\n} as const;\n"]}
1
+ {"version":3,"file":"requestable-context-consumer.js","sourceRoot":"","sources":["src/requestable-context-consumer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAC,SAAS,EAAE,cAAc,EAAC,MAAM,WAAW,CAAC;AAKpD;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,GAAG,eAAe;IAElB;;;;;;;;;OASG;IACH,OAAO,EAAE,cAAc;IAEvB;;;;;;;;OAQG;IACH,IAAI,EAAE,CAA8E,SAAiB,EAAE,EAAE,CAAA,CAAC;QACxG,GAAG,eAAe,CAAC,IAAI,CAAsC,SAAS,CAAC;QAEvE;;;;;;;;;WASG;QACH,QAAQ,EAAE,GAAwC,EAAE,WAClD,OAAA,MAAA,SAAS,CAAsC,SAAS,CAAC,mCAAI,EAAC,KAAK,EAAE,SAAS,EAAC,CAAA,EAAA;QAEjF;;;;;;;;;WASG;QACH,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CACI;KACvC,CAAA;CACH,CAAC","sourcesContent":["import {contextConsumer} from './context-consumer.js';\nimport {getDetail, requestContext} from './core.js';\nimport {RequestableContext} from './type.js';\n\nimport type {Stringifyable, OmitFirstParam} from '@alwatr/type';\n\n/**\n * Requestable context consumer interface.\n */\nexport const requestableContextConsumer = {\n ...contextConsumer,\n\n /**\n * Send new context request to the provider.\n *\n * Example:\n *\n * ```ts\n * requestableContextConsumer.request<RequestParamType>('product-list', {foo: 'bar'});\n * TODO: update me\n * ```\n */\n request: requestContext,\n\n /**\n * Bind this interface to special context.\n *\n * Example:\n *\n * ```ts\n * const productListConsumer = requestableContextConsumer.bind<ProductListType>('product-list');\n * ```\n */\n bind: <TContextContent extends Stringifyable, TRquest extends Stringifyable = null>(contextId: string) =>({\n ...contextConsumer.bind<RequestableContext<TContextContent>>(contextId),\n\n /**\n * Get context value.\n *\n * Example:\n *\n * ```ts\n * const currentProductList = productListConsumer.getValue();\n * TODO: update me\n * ```\n */\n getValue: (): RequestableContext<TContextContent> =>\n getDetail<RequestableContext<TContextContent>>(contextId) ?? {state: 'initial'},\n\n /**\n * Send new context request to the provider.\n *\n * Example:\n *\n * ```ts\n * productListConsumer.request({foo: 'bar'});\n * TODO: update me\n * ```\n */\n request: requestContext.bind(null, contextId) as\n OmitFirstParam<typeof requestContext<TRquest>>,\n } as const),\n} as const;\n"]}
@@ -1,3 +1,4 @@
1
+ import { RequestableContext } from './type.js';
1
2
  import type { Stringifyable } from '@alwatr/type';
2
3
  /**
3
4
  * Requestable context provider interface.
@@ -19,7 +20,7 @@ export declare const requestableContextProvider: {
19
20
  * );
20
21
  * ```
21
22
  */
22
- readonly setProvider: <TContext extends Stringifyable, TRquest extends Stringifyable>(signalId: string, signalProvider: import("./type.js").ProviderFunction<TRquest, void | TContext>, options?: Partial<import("./type.js").ProviderOptions>) => void;
23
+ readonly setProvider: <TContext extends Stringifyable, TRquest extends Stringifyable = null>(signalId: string, signalProvider: import("./type.js").ProviderFunction<TRquest, void | TContext>, options?: Partial<import("./type.js").ProviderOptions>) => void;
23
24
  /**
24
25
  * Bind this interface to special context.
25
26
  *
@@ -29,7 +30,18 @@ export declare const requestableContextProvider: {
29
30
  * const productListProvider = requestableContextProvider.bind<ProductListType>('product-list');
30
31
  * ```
31
32
  */
32
- readonly bind: <TContext_1 extends Stringifyable, TRquest_1 extends Stringifyable>(contextId: string) => {
33
+ readonly bind: <TContextContent extends Stringifyable, TRquest_1 extends Stringifyable = null>(contextId: string) => {
34
+ /**
35
+ * Get context value.
36
+ *
37
+ * Example:
38
+ *
39
+ * ```ts
40
+ * const currentProductList = productListConsumer.getValue();
41
+ * TODO: update me
42
+ * ```
43
+ */
44
+ readonly getValue: () => RequestableContext<TContextContent>;
33
45
  /**
34
46
  * Defines the provider of the context signal that will be called when the context requested.
35
47
  *
@@ -43,14 +55,15 @@ export declare const requestableContextProvider: {
43
55
  * });
44
56
  * ```
45
57
  */
46
- readonly setProvider: (signalProvider: import("./type.js").ProviderFunction<TRquest_1, void | TContext_1>, options?: Partial<import("./type.js").ProviderOptions> | undefined) => void;
58
+ readonly setProvider: (signalProvider: import("./type.js").ProviderFunction<TRquest_1, void | RequestableContext<TContextContent>>, options?: Partial<import("./type.js").ProviderOptions> | undefined) => void;
47
59
  readonly id: string;
48
- readonly getValue: () => TContext_1 | undefined;
49
- readonly setValue: (detail: TContext_1, options?: Partial<import("./type.js").DispatchOptions> | undefined) => void;
60
+ readonly setValue: (detail: RequestableContext<TContextContent>, options?: Partial<import("./type.js").DispatchOptions> | undefined) => void;
50
61
  readonly expire: () => void;
62
+ readonly untilChange: () => Promise<RequestableContext<TContextContent>>;
51
63
  };
52
64
  readonly getValue: <T extends Stringifyable>(signalId: string) => T | undefined;
53
65
  readonly setValue: <T_1 extends Stringifyable>(signalId: string, detail: T_1, options?: Partial<import("./type.js").DispatchOptions>) => void;
54
66
  readonly expire: (signalId: string) => void;
67
+ readonly untilChange: <T_2 extends Stringifyable>(signalId: string) => Promise<T_2>;
55
68
  };
56
69
  //# sourceMappingURL=requestable-context-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"requestable-context-provider.d.ts","sourceRoot":"","sources":["src/requestable-context-provider.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,aAAa,EAAiB,MAAM,cAAc,CAAC;AAEhE;;GAEG;AACH,eAAO,MAAM,0BAA0B;IAGrC;;;;;;;;;;;;;;;OAeG;;IAGH;;;;;;;;OAQG;kGAC8E,MAAM;QAGrF;;;;;;;;;;;;WAYG;;;;;;;;;;CAIG,CAAC"}
1
+ {"version":3,"file":"requestable-context-provider.d.ts","sourceRoot":"","sources":["src/requestable-context-provider.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,kBAAkB,EAAC,MAAM,WAAW,CAAC;AAE7C,OAAO,KAAK,EAAC,aAAa,EAAiB,MAAM,cAAc,CAAC;AAEhE;;GAEG;AACH,eAAO,MAAM,0BAA0B;IAGrC;;;;;;;;;;;;;;;OAeG;;IAGH;;;;;;;;OAQG;8GAC4F,MAAM;QAGnG;;;;;;;;;WASG;;QAKH;;;;;;;;;;;;WAYG;;;;;;;;;;;CAIG,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { contextProvider } from './context-provider.js';
2
- import { setContextProvider } from './core.js';
2
+ import { getDetail, setContextProvider } from './core.js';
3
3
  /**
4
4
  * Requestable context provider interface.
5
5
  */
@@ -33,6 +33,17 @@ export const requestableContextProvider = {
33
33
  */
34
34
  bind: (contextId) => ({
35
35
  ...contextProvider.bind(contextId),
36
+ /**
37
+ * Get context value.
38
+ *
39
+ * Example:
40
+ *
41
+ * ```ts
42
+ * const currentProductList = productListConsumer.getValue();
43
+ * TODO: update me
44
+ * ```
45
+ */
46
+ getValue: () => { var _a; return (_a = getDetail(contextId)) !== null && _a !== void 0 ? _a : { state: 'initial' }; },
36
47
  /**
37
48
  * Defines the provider of the context signal that will be called when the context requested.
38
49
  *
@@ -1 +1 @@
1
- {"version":3,"file":"requestable-context-provider.js","sourceRoot":"","sources":["src/requestable-context-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAC,kBAAkB,EAAC,MAAM,WAAW,CAAC;AAI7C;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,GAAG,eAAe;IAElB;;;;;;;;;;;;;;;OAeG;IACH,WAAW,EAAE,kBAAkB;IAE/B;;;;;;;;OAQG;IACH,IAAI,EAAE,CAAgE,SAAiB,EAAE,EAAE,CAAA,CAAC;QAC1F,GAAG,eAAe,CAAC,IAAI,CAAW,SAAS,CAAC;QAE5C;;;;;;;;;;;;WAYG;QACH,WAAW,EAAE,kBAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CACU;KACrD,CAAA;CACH,CAAC","sourcesContent":["import {contextProvider} from './context-provider.js';\nimport {setContextProvider} from './core.js';\n\nimport type {Stringifyable, OmitFirstParam} from '@alwatr/type';\n\n/**\n * Requestable context provider interface.\n */\nexport const requestableContextProvider = {\n ...contextProvider,\n\n /**\n * Defines the provider of the context signal that will be called when the context requested.\n *\n * subscribe to request context signal.\n *\n * Example:\n *\n * ```ts\n * requestableContextProvider.setProvider<ProductListType, RequestParamType>(\n * 'product-list',\n * async (requestParam) => {\n * return await fetchNewProductList(requestParam)\n * },\n * );\n * ```\n */\n setProvider: setContextProvider,\n\n /**\n * Bind this interface to special context.\n *\n * Example:\n *\n * ```ts\n * const productListProvider = requestableContextProvider.bind<ProductListType>('product-list');\n * ```\n */\n bind: <TContext extends Stringifyable, TRquest extends Stringifyable>(contextId: string) =>({\n ...contextProvider.bind<TContext>(contextId),\n\n /**\n * Defines the provider of the context signal that will be called when the context requested.\n *\n * subscribe to request context signal.\n *\n * Example:\n *\n * ```ts\n * productListProvider.setProvider(async (requestParam) => {\n * return await fetchNewProductList(requestParam)\n * });\n * ```\n */\n setProvider: setContextProvider.bind(null, contextId) as\n OmitFirstParam<typeof setContextProvider<TContext, TRquest>>,\n } as const),\n} as const;\n"]}
1
+ {"version":3,"file":"requestable-context-provider.js","sourceRoot":"","sources":["src/requestable-context-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAC,SAAS,EAAE,kBAAkB,EAAC,MAAM,WAAW,CAAC;AAKxD;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,GAAG,eAAe;IAElB;;;;;;;;;;;;;;;OAeG;IACH,WAAW,EAAE,kBAAkB;IAE/B;;;;;;;;OAQG;IACH,IAAI,EAAE,CAA8E,SAAiB,EAAE,EAAE,CAAA,CAAC;QACxG,GAAG,eAAe,CAAC,IAAI,CAAsC,SAAS,CAAC;QAEvE;;;;;;;;;WASG;QACH,QAAQ,EAAE,GAAwC,EAAE,WAClD,OAAA,MAAA,SAAS,CAAsC,SAAS,CAAC,mCAAI,EAAC,KAAK,EAAE,SAAS,EAAC,CAAA,EAAA;QAGjF;;;;;;;;;;;;WAYG;QACH,WAAW,EAAE,kBAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CACqC;KAChF,CAAA;CACH,CAAC","sourcesContent":["import {contextProvider} from './context-provider.js';\nimport {getDetail, setContextProvider} from './core.js';\nimport {RequestableContext} from './type.js';\n\nimport type {Stringifyable, OmitFirstParam} from '@alwatr/type';\n\n/**\n * Requestable context provider interface.\n */\nexport const requestableContextProvider = {\n ...contextProvider,\n\n /**\n * Defines the provider of the context signal that will be called when the context requested.\n *\n * subscribe to request context signal.\n *\n * Example:\n *\n * ```ts\n * requestableContextProvider.setProvider<ProductListType, RequestParamType>(\n * 'product-list',\n * async (requestParam) => {\n * return await fetchNewProductList(requestParam)\n * },\n * );\n * ```\n */\n setProvider: setContextProvider,\n\n /**\n * Bind this interface to special context.\n *\n * Example:\n *\n * ```ts\n * const productListProvider = requestableContextProvider.bind<ProductListType>('product-list');\n * ```\n */\n bind: <TContextContent extends Stringifyable, TRquest extends Stringifyable = null>(contextId: string) =>({\n ...contextProvider.bind<RequestableContext<TContextContent>>(contextId),\n\n /**\n * Get context value.\n *\n * Example:\n *\n * ```ts\n * const currentProductList = productListConsumer.getValue();\n * TODO: update me\n * ```\n */\n getValue: (): RequestableContext<TContextContent> =>\n getDetail<RequestableContext<TContextContent>>(contextId) ?? {state: 'initial'},\n\n\n /**\n * Defines the provider of the context signal that will be called when the context requested.\n *\n * subscribe to request context signal.\n *\n * Example:\n *\n * ```ts\n * productListProvider.setProvider(async (requestParam) => {\n * return await fetchNewProductList(requestParam)\n * });\n * ```\n */\n setProvider: setContextProvider.bind(null, contextId) as\n OmitFirstParam<typeof setContextProvider<RequestableContext<TContextContent>, TRquest>>,\n } as const),\n} as const;\n"]}
package/type.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { MaybePromise, Stringifyable } from '@alwatr/type';
2
- export type DebounceType = 'No' | 'AnimationFrame' | 'Timeout';
1
+ import type { MaybePromise, Stringifyable } from '@alwatr/type';
2
+ export type DebounceType = 'No' | 'NextCycle' | 'AnimationFrame' | 'Timeout';
3
3
  /**
4
4
  * Subscribe options type.
5
5
  */
@@ -24,18 +24,20 @@ export interface SubscribeOptions {
24
24
  * Calling this listener (callback) with preview signal value (if dispatched before).
25
25
  * If Immediate, the listener will be called immediately without any debounce for preview signal.
26
26
  *
27
- * @default `AnimationFrame`
27
+ * @default `NextCycle`
28
28
  */
29
- receivePrevious: DebounceType | 'NextCycle';
29
+ receivePrevious: DebounceType;
30
30
  }
31
31
  /**
32
32
  * dispatchSignal options type
33
33
  */
34
34
  export interface DispatchOptions {
35
35
  /**
36
- * If true, the dispatch will be send after animation frame debounce.
37
- * If false, every signal is matter and count.
38
- * tips: debounce work like throttle this means listeners call with last dispatch value.
36
+ * If 'AnimationFrame' or 'Timeout', the dispatch will be debounced (single dispatch for all changes).
37
+ *
38
+ * If 'No' or 'NextCycle', every signal is matter and count without debounced (every changes dispatched).
39
+ *
40
+ * tips: debounce work like throttle this means listeners call with latest dispatch value.
39
41
  *
40
42
  * @default `AnimationFrame`
41
43
  */
@@ -51,11 +53,13 @@ export interface ProviderOptions {
51
53
  *
52
54
  * @default `NextCycle`
53
55
  */
54
- receivePrevious: DebounceType | 'NextCycle';
56
+ receivePrevious: DebounceType;
55
57
  /**
56
- * If true, the dispatch will be send after animation frame debounce.
57
- * If false, every signal is matter and count.
58
- * tips: debounce true work like throttle this means listeners call with last dispatch value.
58
+ * If 'AnimationFrame' or 'Timeout', the dispatch will be debounced (single dispatch for all changes).
59
+ *
60
+ * If 'No' or 'NextCycle', every signal is matter and count without debounced (every changes dispatched).
61
+ *
62
+ * tips: debounce work like throttle this means listeners call with latest dispatch value.
59
63
  *
60
64
  * @default `AnimationFrame`
61
65
  */
@@ -126,4 +130,17 @@ export type SignalObject<T extends Stringifyable> = {
126
130
  * Signal stack storage.
127
131
  */
128
132
  export type SignalStorage = Record<string, SignalObject<Stringifyable> | undefined>;
133
+ /**
134
+ * Requestable context value type.
135
+ */
136
+ export type RequestableContext<T extends Stringifyable> = {
137
+ state: 'initial' | 'pending';
138
+ content?: never;
139
+ } | {
140
+ state: 'error';
141
+ content?: T;
142
+ } | {
143
+ state: 'complete' | 'reloading';
144
+ content: T;
145
+ };
129
146
  //# sourceMappingURL=type.d.ts.map
package/type.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,aAAa,EAAC,MAAM,cAAc,CAAC;AAEzD,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,gBAAgB,GAAG,SAAS,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,IAAI,EAAE,OAAO,CAAC;IAEd;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;;;;OAKG;IACH,eAAe,EAAE,YAAY,GAAG,WAAW,CAAC;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,eAAe,EAAE,YAAY,GAAG,WAAW,CAAC;IAE5C;;;;;;OAMG;IACH,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,aAAa,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5F;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,SAAS,EAAE,OAAO,IAAI,CACjD,cAAc,EAAE,SAAS,KACtB,YAAY,CAAC,OAAO,C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xC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC,CAAC;AAEpF;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,aAAa,IAClD;IACE,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC;IAC7B,OAAO,CAAC,EAAE,KAAK,CAAC;CACjB,GACD;IACE,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,CAAC,CAAC;CACb,GACD;IACE,KAAK,EAAE,UAAU,GAAG,WAAW,CAAC;IAChC,OAAO,EAAE,CAAC,CAAC;CACZ,CAAC"}
package/type.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"type.js","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":"","sourcesContent":["import {MaybePromise, Stringifyable} from '@alwatr/type';\n\nexport type DebounceType = 'No' | 'AnimationFrame' | 'Timeout';\n\n/**\n * Subscribe options type.\n */\nexport interface SubscribeOptions {\n /**\n * If true, the listener will be called only once.\n * @default false\n */\n once: boolean;\n\n /**\n * If true, the listener will be called before other.\n * @default false\n */\n priority: boolean;\n\n /**\n * If true, the listener will be defined disabled by default.\n *\n * @default false\n */\n disabled: boolean;\n\n /**\n * Calling this listener (callback) with preview signal value (if dispatched before).\n * If Immediate, the listener will be called immediately without any debounce for preview signal.\n *\n * @default `AnimationFrame`\n */\n receivePrevious: DebounceType | 'NextCycle';\n}\n\n/**\n * dispatchSignal options type\n */\nexport interface DispatchOptions {\n /**\n * If true, the dispatch will be send after animation frame debounce.\n * If false, every signal is matter and count.\n * tips: debounce work like throttle this means listeners call with last dispatch value.\n *\n * @default `AnimationFrame`\n */\n debounce: DebounceType;\n}\n\n/**\n * setSignalProvider options type.\n */\nexport interface ProviderOptions {\n /**\n * Calling signal provider (request signal callback) with preview signal value (if dispatched before).\n * If Immediate, the listener will be called immediately without any debounce for preview signal.\n *\n * @default `NextCycle`\n */\n receivePrevious: DebounceType | 'NextCycle';\n\n /**\n * If true, the dispatch will be send after animation frame debounce.\n * If false, every signal is matter and count.\n * tips: debounce true work like throttle this means listeners call with last dispatch value.\n *\n * @default `AnimationFrame`\n */\n debounce: DebounceType;\n}\n\n/**\n * Subscribe callback function.\n */\nexport type ListenerFunction<T extends Stringifyable> = (detail: T) => void | Promise<void>;\n\n/**\n * Command/Context provider/handler function.\n */\nexport type ProviderFunction<TArgument, TReturn> = (\n argumentObject: TArgument\n) => MaybePromise<TReturn>;\n\n/**\n * Listener spec.\n */\nexport type ListenerSpec = {\n /**\n * Unique listener id\n */\n id: number;\n\n /**\n * Signal id\n */\n signalId: string;\n}\n\n/**\n * Signal listeners object in storage.\n */\nexport type ListenerObject<T extends Stringifyable> = ListenerSpec & {\n /**\n * If true, the listener will be called only once and removed automatically after first call\n */\n once: boolean;\n\n /**\n * If true, the listener will be disabled.\n */\n disabled: boolean;\n\n callback: ListenerFunction<T>;\n};\n\n/**\n * Signal object in storage.\n */\nexport type SignalObject<T extends Stringifyable> = {\n /**\n * Signal id for direct access.\n */\n id: string;\n\n /**\n * Last dispatched detail.\n */\n detail?: T;\n\n /**\n * If true, the signal is disabled.\n */\n disabled: boolean;\n\n /**\n * Dispatches debounced (delayed).\n * Internal use case for debounce dispatch signal.\n */\n debounced: boolean;\n\n /**\n * Signal listeners list.\n */\n listenerList: Array<ListenerObject<T>>;\n};\n\n/**\n * Signal stack storage.\n */\nexport type SignalStorage = Record<string, SignalObject<Stringifyable> | undefined>;\n"]}
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":"","sourcesContent":["import type {MaybePromise, Stringifyable} from '@alwatr/type';\n\nexport type DebounceType = 'No' | 'NextCycle' | 'AnimationFrame' | 'Timeout';\n\n/**\n * Subscribe options type.\n */\nexport interface SubscribeOptions {\n /**\n * If true, the listener will be called only once.\n * @default false\n */\n once: boolean;\n\n /**\n * If true, the listener will be called before other.\n * @default false\n */\n priority: boolean;\n\n /**\n * If true, the listener will be defined disabled by default.\n *\n * @default false\n */\n disabled: boolean;\n\n /**\n * Calling this listener (callback) with preview signal value (if dispatched before).\n * If Immediate, the listener will be called immediately without any debounce for preview signal.\n *\n * @default `NextCycle`\n */\n receivePrevious: DebounceType;\n}\n\n/**\n * dispatchSignal options type\n */\nexport interface DispatchOptions {\n /**\n * If 'AnimationFrame' or 'Timeout', the dispatch will be debounced (single dispatch for all changes).\n *\n * If 'No' or 'NextCycle', every signal is matter and count without debounced (every changes dispatched).\n *\n * tips: debounce work like throttle this means listeners call with latest dispatch value.\n *\n * @default `AnimationFrame`\n */\n debounce: DebounceType;\n}\n\n/**\n * setSignalProvider options type.\n */\nexport interface ProviderOptions {\n /**\n * Calling signal provider (request signal callback) with preview signal value (if dispatched before).\n * If Immediate, the listener will be called immediately without any debounce for preview signal.\n *\n * @default `NextCycle`\n */\n receivePrevious: DebounceType;\n\n /**\n * If 'AnimationFrame' or 'Timeout', the dispatch will be debounced (single dispatch for all changes).\n *\n * If 'No' or 'NextCycle', every signal is matter and count without debounced (every changes dispatched).\n *\n * tips: debounce work like throttle this means listeners call with latest dispatch value.\n *\n * @default `AnimationFrame`\n */\n debounce: DebounceType;\n}\n\n/**\n * Subscribe callback function.\n */\nexport type ListenerFunction<T extends Stringifyable> = (detail: T) => void | Promise<void>;\n\n/**\n * Command/Context provider/handler function.\n */\nexport type ProviderFunction<TArgument, TReturn> = (argumentObject: TArgument) => MaybePromise<TReturn>;\n\n/**\n * Listener spec.\n */\nexport type ListenerSpec = {\n /**\n * Unique listener id\n */\n id: number;\n\n /**\n * Signal id\n */\n signalId: string;\n};\n\n/**\n * Signal listeners object in storage.\n */\nexport type ListenerObject<T extends Stringifyable> = ListenerSpec & {\n /**\n * If true, the listener will be called only once and removed automatically after first call\n */\n once: boolean;\n\n /**\n * If true, the listener will be disabled.\n */\n disabled: boolean;\n\n callback: ListenerFunction<T>;\n};\n\n/**\n * Signal object in storage.\n */\nexport type SignalObject<T extends Stringifyable> = {\n /**\n * Signal id for direct access.\n */\n id: string;\n\n /**\n * Last dispatched detail.\n */\n detail?: T;\n\n /**\n * If true, the signal is disabled.\n */\n disabled: boolean;\n\n /**\n * Dispatches debounced (delayed).\n * Internal use case for debounce dispatch signal.\n */\n debounced: boolean;\n\n /**\n * Signal listeners list.\n */\n listenerList: Array<ListenerObject<T>>;\n};\n\n/**\n * Signal stack storage.\n */\nexport type SignalStorage = Record<string, SignalObject<Stringifyable> | undefined>;\n\n/**\n * Requestable context value type.\n */\nexport type RequestableContext<T extends Stringifyable> =\n | {\n state: 'initial' | 'pending';\n content?: never;\n }\n | {\n state: 'error';\n content?: T; // last data\n }\n | {\n state: 'complete' | 'reloading';\n content: T;\n };\n"]}