@alwatr/signal 1.1.2 → 2.0.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.
Files changed (65) hide show
  1. package/CHANGELOG.md +173 -163
  2. package/context.d.ts +31 -0
  3. package/context.d.ts.map +1 -0
  4. package/context.js +40 -0
  5. package/context.js.map +1 -0
  6. package/index.d.ts +5 -9
  7. package/index.d.ts.map +1 -1
  8. package/index.js +10 -16
  9. package/index.js.map +1 -1
  10. package/multithread-context.d.ts +21 -0
  11. package/multithread-context.d.ts.map +1 -0
  12. package/multithread-context.js +50 -0
  13. package/multithread-context.js.map +1 -0
  14. package/observable.d.ts +47 -0
  15. package/observable.d.ts.map +1 -0
  16. package/observable.js +126 -0
  17. package/observable.js.map +1 -0
  18. package/package.json +9 -9
  19. package/signal.d.ts +19 -0
  20. package/signal.d.ts.map +1 -0
  21. package/signal.js +23 -0
  22. package/signal.js.map +1 -0
  23. package/simple-signal.d.ts +19 -0
  24. package/simple-signal.d.ts.map +1 -0
  25. package/simple-signal.js +23 -0
  26. package/simple-signal.js.map +1 -0
  27. package/type.d.ts +15 -126
  28. package/type.d.ts.map +1 -1
  29. package/type.js.map +1 -1
  30. package/command-handler.d.ts +0 -25
  31. package/command-handler.d.ts.map +0 -1
  32. package/command-handler.js +0 -24
  33. package/command-handler.js.map +0 -1
  34. package/command-trigger.d.ts +0 -64
  35. package/command-trigger.d.ts.map +0 -1
  36. package/command-trigger.js +0 -64
  37. package/command-trigger.js.map +0 -1
  38. package/context-consumer.d.ts +0 -124
  39. package/context-consumer.d.ts.map +0 -1
  40. package/context-consumer.js +0 -124
  41. package/context-consumer.js.map +0 -1
  42. package/context-provider.d.ts +0 -120
  43. package/context-provider.d.ts.map +0 -1
  44. package/context-provider.js +0 -120
  45. package/context-provider.js.map +0 -1
  46. package/core.d.ts +0 -181
  47. package/core.d.ts.map +0 -1
  48. package/core.js +0 -388
  49. package/core.js.map +0 -1
  50. package/event-listener.d.ts +0 -120
  51. package/event-listener.d.ts.map +0 -1
  52. package/event-listener.js +0 -120
  53. package/event-listener.js.map +0 -1
  54. package/event-trigger.d.ts +0 -76
  55. package/event-trigger.d.ts.map +0 -1
  56. package/event-trigger.js +0 -76
  57. package/event-trigger.js.map +0 -1
  58. package/requestable-context-consumer.d.ts +0 -60
  59. package/requestable-context-consumer.d.ts.map +0 -1
  60. package/requestable-context-consumer.js +0 -54
  61. package/requestable-context-consumer.js.map +0 -1
  62. package/requestable-context-provider.d.ts +0 -69
  63. package/requestable-context-provider.d.ts.map +0 -1
  64. package/requestable-context-provider.js +0 -63
  65. package/requestable-context-provider.js.map +0 -1
package/context.js ADDED
@@ -0,0 +1,40 @@
1
+ import { AlwatrObservable } from './observable.js';
2
+ /**
3
+ * Alwatr context signal.
4
+ */
5
+ export class AlwatrContextSignal extends AlwatrObservable {
6
+ constructor(config) {
7
+ config.loggerPrefix ?? (config.loggerPrefix = 'context-signal');
8
+ super(config);
9
+ }
10
+ /**
11
+ * Get context value.
12
+ *
13
+ * Return undefined if context not set before or expired.
14
+ */
15
+ getValue() {
16
+ return super._getData();
17
+ }
18
+ /**
19
+ * Set context value and notify all subscribers.
20
+ */
21
+ setValue(value) {
22
+ this._logger.logMethodArgs?.('setValue', { value });
23
+ super._notify(value);
24
+ }
25
+ /**
26
+ * Clear current context value without notify subscribers.
27
+ *
28
+ * `receivePrevious` in new subscribers not work until new context changes.
29
+ */
30
+ expire() {
31
+ super._clear();
32
+ }
33
+ /**
34
+ * Get the value of the next context changes.
35
+ */
36
+ untilChange() {
37
+ return super._untilNewNotify();
38
+ }
39
+ }
40
+ //# sourceMappingURL=context.js.map
package/context.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAEjD;;GAEG;AACH,MAAM,OAAO,mBAAuB,SAAQ,gBAAmB;IAC7D,YAAY,MAA6C;QACvD,MAAM,CAAC,YAAY,KAAnB,MAAM,CAAC,YAAY,GAAK,gBAAgB,EAAC;QACzC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACH,QAAQ;QACN,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,KAAQ;QACf,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,UAAU,EAAE,EAAC,KAAK,EAAC,CAAC,CAAC;QAClD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,KAAK,CAAC,MAAM,EAAE,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,KAAK,CAAC,eAAe,EAAE,CAAC;IACjC,CAAC;CACF","sourcesContent":["import {AlwatrObservable} from './observable.js';\n\n/**\n * Alwatr context signal.\n */\nexport class AlwatrContextSignal<T> extends AlwatrObservable<T> {\n constructor(config: {name: string; loggerPrefix?: string}) {\n config.loggerPrefix ??= 'context-signal';\n super(config);\n }\n\n /**\n * Get context value.\n *\n * Return undefined if context not set before or expired.\n */\n getValue(): T | undefined {\n return super._getData();\n }\n\n /**\n * Set context value and notify all subscribers.\n */\n setValue(value: T): void {\n this._logger.logMethodArgs?.('setValue', {value});\n super._notify(value);\n }\n\n /**\n * Clear current context value without notify subscribers.\n *\n * `receivePrevious` in new subscribers not work until new context changes.\n */\n expire(): void {\n super._clear();\n }\n\n /**\n * Get the value of the next context changes.\n */\n untilChange(): Promise<T> {\n return super._untilNewNotify();\n }\n}\n"]}
package/index.d.ts CHANGED
@@ -1,10 +1,6 @@
1
- export * from './command-handler.js';
2
- export * from './command-trigger.js';
3
- export * from './context-consumer.js';
4
- export * from './context-provider.js';
5
- export * from './event-listener.js';
6
- export * from './event-trigger.js';
7
- export * from './requestable-context-consumer.js';
8
- export * from './requestable-context-provider.js';
9
- export type { ListenerSpec, DebounceType, DispatchOptions } from './type.js';
1
+ export * from './simple-signal.js';
2
+ export * from './signal.js';
3
+ export * from './context.js';
4
+ export * from './multithread-context.js';
5
+ export * from './type.js';
10
6
  //# 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,EAAE,YAAY,EAAE,eAAe,EAAC,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAEA,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,0BAA0B,CAAC;AACzC,cAAc,WAAW,CAAC"}
package/index.js CHANGED
@@ -1,17 +1,11 @@
1
- export * from './command-handler.js';
2
- export * from './command-trigger.js';
3
- export * from './context-consumer.js';
4
- export * from './context-provider.js';
5
- export * from './event-listener.js';
6
- export * from './event-trigger.js';
7
- export * from './requestable-context-consumer.js';
8
- export * from './requestable-context-provider.js';
9
- /*
10
- TODO:
11
- 1. change signal option like disable
12
- 2. Get signal value without undefined
13
- (Get signal value from last dispatched signal (if any) or wait for new signal received.)
14
- 3. dispatched bool
15
- 4. optional commandProvider debounce
16
- */
1
+ import { globalAlwatr } from '@alwatr/logger';
2
+ export * from './simple-signal.js';
3
+ export * from './signal.js';
4
+ export * from './context.js';
5
+ export * from './multithread-context.js';
6
+ export * from './type.js';
7
+ globalAlwatr.registeredList.push({
8
+ name: '@alwatr/signal',
9
+ version: _ALWATR_VERSION_,
10
+ });
17
11
  //# sourceMappingURL=index.js.map
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, 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"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,0BAA0B,CAAC;AACzC,cAAc,WAAW,CAAC;AAE1B,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC;IAC/B,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,gBAAgB;CAC1B,CAAC,CAAC","sourcesContent":["import {globalAlwatr} from '@alwatr/logger';\n\nexport * from './simple-signal.js';\nexport * from './signal.js';\nexport * from './context.js';\nexport * from './multithread-context.js';\nexport * from './type.js';\n\nglobalAlwatr.registeredList.push({\n name: '@alwatr/signal',\n version: _ALWATR_VERSION_,\n});\n"]}
@@ -0,0 +1,21 @@
1
+ import { AlwatrContextSignal } from './context.js';
2
+ /**
3
+ * Alwatr multithread context signal.
4
+ */
5
+ export declare class AlwatrMultithreadContextSignal<TValue> extends AlwatrContextSignal<TValue> {
6
+ protected static _logger: import("@alwatr/logger").AlwatrLogger;
7
+ protected static _worker?: Worker;
8
+ protected static _registry: Record<string, AlwatrMultithreadContextSignal<unknown> | undefined>;
9
+ static setupChannel(worker?: Worker): void;
10
+ static _onMessage(event: MessageEvent): void;
11
+ static _postMessage(name: string, payload: unknown): void;
12
+ constructor(config: {
13
+ name: string;
14
+ loggerPrefix?: string;
15
+ });
16
+ /**
17
+ * Set context value and notify all subscribers.
18
+ */
19
+ setValue(value: TValue): void;
20
+ }
21
+ //# sourceMappingURL=multithread-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multithread-context.d.ts","sourceRoot":"","sources":["src/multithread-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,mBAAmB,EAAC,MAAM,cAAc,CAAC;AAQjD;;GAEG;AACH,qBAAa,8BAA8B,CAAC,MAAM,CAAE,SAAQ,mBAAmB,CAAC,MAAM,CAAC;IACrF,SAAS,CAAC,MAAM,CAAC,OAAO,wCAAqC;IAC7D,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAClC,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,8BAA8B,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAM;IAErG,MAAM,CAAC,YAAY,CAAC,MAAM,GAAE,MAAkC,GAAG,IAAI;IAKrE,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAW5C,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;gBAY7C,MAAM,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAC;IAUzD;;OAEG;IACM,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAIvC"}
@@ -0,0 +1,50 @@
1
+ import { createLogger } from '@alwatr/logger';
2
+ import { AlwatrContextSignal } from './context.js';
3
+ /**
4
+ * Alwatr multithread context signal.
5
+ */
6
+ export class AlwatrMultithreadContextSignal extends AlwatrContextSignal {
7
+ static setupChannel(worker = self) {
8
+ AlwatrMultithreadContextSignal._worker = worker;
9
+ worker.addEventListener('message', AlwatrMultithreadContextSignal._onMessage);
10
+ }
11
+ static _onMessage(event) {
12
+ const message = event.data;
13
+ if (message.type !== 'alwatr_context_changed')
14
+ return;
15
+ AlwatrMultithreadContextSignal._logger.logMethodArgs?.('_onMessage', { message });
16
+ const context = AlwatrMultithreadContextSignal._registry[message.name];
17
+ if (context === undefined) {
18
+ throw new Error('context_not_define', { cause: 'context not define in this thread yet!' });
19
+ }
20
+ context._notify(message.payload);
21
+ }
22
+ static _postMessage(name, payload) {
23
+ AlwatrMultithreadContextSignal._logger.logMethodArgs?.('_postMessage', { name, payload });
24
+ if (AlwatrMultithreadContextSignal._worker === undefined) {
25
+ throw new Error('worker_not_defined', { cause: 'setupChannel must be called before any setValue.' });
26
+ }
27
+ AlwatrMultithreadContextSignal._worker.postMessage({
28
+ type: 'alwatr_context_changed',
29
+ name,
30
+ payload,
31
+ });
32
+ }
33
+ constructor(config) {
34
+ super(config);
35
+ if (AlwatrMultithreadContextSignal._registry[this._name] !== undefined) {
36
+ throw new Error('context_name_exist');
37
+ }
38
+ AlwatrMultithreadContextSignal._registry[this._name] = this;
39
+ }
40
+ /**
41
+ * Set context value and notify all subscribers.
42
+ */
43
+ setValue(value) {
44
+ super.setValue(value);
45
+ AlwatrMultithreadContextSignal._postMessage(this._name, value);
46
+ }
47
+ }
48
+ AlwatrMultithreadContextSignal._logger = createLogger(`alwatr/mt-context`);
49
+ AlwatrMultithreadContextSignal._registry = {};
50
+ //# sourceMappingURL=multithread-context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AAC,CAAC;SACpG;QACD,8BAA8B,CAAC,OAAO,CAAC,WAAW,CAAC;YACjD,IAAI,EAAE,wBAAwB;YAC9B,IAAI;YACJ,OAAO;SACuB,CAAC,CAAC;IACpC,CAAC;IAED,YAAY,MAA6C;QACvD,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,8BAA8B,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,SAAS,EAAE;YACtE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;SACvC;QAED,8BAA8B,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,IAA+C,CAAC;IACzG,CAAC;IAED;;OAEG;IACM,QAAQ,CAAC,KAAa;QAC7B,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACtB,8BAA8B,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACjE,CAAC;;AAhDgB,sCAAO,GAAG,YAAY,CAAC,mBAAmB,CAAC,CAAC;AAE5C,wCAAS,GAAwE,EAAE,CAAC","sourcesContent":["import {createLogger} from '@alwatr/logger';\n\nimport {AlwatrContextSignal} from './context.js';\n\ninterface AlwatrContextChangedMessage {\n type: 'alwatr_context_changed';\n name: string;\n payload: unknown;\n}\n\n/**\n * Alwatr multithread context signal.\n */\nexport class AlwatrMultithreadContextSignal<TValue> extends AlwatrContextSignal<TValue> {\n protected static _logger = createLogger(`alwatr/mt-context`);\n protected static _worker?: Worker;\n protected static _registry: Record<string, AlwatrMultithreadContextSignal<unknown> | undefined> = {};\n\n static setupChannel(worker: Worker = self as unknown as Worker): void {\n AlwatrMultithreadContextSignal._worker = worker;\n worker.addEventListener('message', AlwatrMultithreadContextSignal._onMessage);\n }\n\n static _onMessage(event: MessageEvent): void {\n const message = event.data as AlwatrContextChangedMessage;\n if (message.type !== 'alwatr_context_changed') return;\n AlwatrMultithreadContextSignal._logger.logMethodArgs?.('_onMessage', {message});\n const context = AlwatrMultithreadContextSignal._registry[message.name];\n if (context === undefined) {\n throw new Error('context_not_define', {cause: 'context not define in this thread yet!'});\n }\n context._notify(message.payload);\n }\n\n static _postMessage(name: string, payload: unknown): void {\n AlwatrMultithreadContextSignal._logger.logMethodArgs?.('_postMessage', {name, payload});\n if (AlwatrMultithreadContextSignal._worker === undefined) {\n throw new Error('worker_not_defined', {cause: 'setupChannel must be called before any setValue.'});\n }\n AlwatrMultithreadContextSignal._worker.postMessage({\n type: 'alwatr_context_changed',\n name,\n payload,\n } as AlwatrContextChangedMessage);\n }\n\n constructor(config: {name: string; loggerPrefix?: string}) {\n super(config);\n\n if (AlwatrMultithreadContextSignal._registry[this._name] !== undefined) {\n throw new Error('context_name_exist');\n }\n\n AlwatrMultithreadContextSignal._registry[this._name] = this as AlwatrMultithreadContextSignal<unknown>;\n }\n\n /**\n * Set context value and notify all subscribers.\n */\n override setValue(value: TValue): void {\n super.setValue(value);\n AlwatrMultithreadContextSignal._postMessage(this._name, value);\n }\n}\n"]}
@@ -0,0 +1,47 @@
1
+ import type { SubscribeOptions, ListenerCallback, Observer, SubscribeResult, AlwatrObservableInterface } from './type.js';
2
+ /**
3
+ * Alwatr base signal.
4
+ */
5
+ export declare abstract class AlwatrObservable<T> implements AlwatrObservableInterface<T> {
6
+ protected _name: string;
7
+ protected _logger: import("@alwatr/logger").AlwatrLogger;
8
+ protected _$data?: T;
9
+ protected _$observers: Observer<this, T>[];
10
+ constructor(config: {
11
+ name: string;
12
+ loggerPrefix?: string;
13
+ });
14
+ /**
15
+ * Get data.
16
+ *
17
+ * Return undefined if signal not notify before or expired.
18
+ */
19
+ protected _getData(): T | undefined;
20
+ /**
21
+ * Execute all observers and remember data.
22
+ */
23
+ protected _notify(data: T): void;
24
+ /**
25
+ * Execute all observers callback.
26
+ */
27
+ protected _$dispatch(data: T): void;
28
+ /**
29
+ * Subscribe to context changes.
30
+ */
31
+ subscribe(listenerCallback: ListenerCallback<this, T>, options?: SubscribeOptions): SubscribeResult;
32
+ /**
33
+ * Unsubscribe from context.
34
+ */
35
+ unsubscribe(listenerCallback: ListenerCallback<this, T>): void;
36
+ /**
37
+ * Clear current data without notify subscribers.
38
+ *
39
+ * `receivePrevious` in new subscribers not work until new a notify changes the data.
40
+ */
41
+ protected _clear(): void;
42
+ /**
43
+ * Get the data of next notify.
44
+ */
45
+ protected _untilNewNotify(): Promise<T>;
46
+ }
47
+ //# sourceMappingURL=observable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observable.d.ts","sourceRoot":"","sources":["src/observable.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,eAAe,EACf,yBAAyB,EAC1B,MAAM,WAAW,CAAC;AAEnB;;GAEG;AACH,8BAAsB,gBAAgB,CAAC,CAAC,CAAE,YAAW,yBAAyB,CAAC,CAAC,CAAC;IAC/E,SAAS,CAAC,KAAK,SAAC;IAChB,SAAS,CAAC,OAAO,wCAAC;IAClB,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACrB,SAAS,CAAC,WAAW,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAM;gBAEpC,MAAM,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAC;IAOzD;;;;OAIG;IACH,SAAS,CAAC,QAAQ,IAAI,CAAC,GAAG,SAAS;IAKnC;;OAEG;IACH,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAMhC;;OAEG;IACH,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAuBnC;;OAEG;IACH,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,GAAE,gBAAqB,GAAG,eAAe;IAyCvG;;OAEG;IACH,WAAW,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI;IAQ9D;;;;OAIG;IACH,SAAS,CAAC,MAAM,IAAI,IAAI;IAKxB;;OAEG;IACH,SAAS,CAAC,eAAe,IAAI,OAAO,CAAC,CAAC,CAAC;CAUxC"}
package/observable.js ADDED
@@ -0,0 +1,126 @@
1
+ import { createLogger } from '@alwatr/logger';
2
+ /**
3
+ * Alwatr base signal.
4
+ */
5
+ export class AlwatrObservable {
6
+ constructor(config) {
7
+ this._$observers = [];
8
+ config.loggerPrefix ?? (config.loggerPrefix = 'signal');
9
+ this._name = config.name;
10
+ this._logger = createLogger(`{${config.loggerPrefix}: ${this._name}}`);
11
+ this._logger.logMethod?.('constructor');
12
+ }
13
+ /**
14
+ * Get data.
15
+ *
16
+ * Return undefined if signal not notify before or expired.
17
+ */
18
+ _getData() {
19
+ this._logger.logMethodFull?.('_getData', {}, this._$data);
20
+ return this._$data;
21
+ }
22
+ /**
23
+ * Execute all observers and remember data.
24
+ */
25
+ _notify(data) {
26
+ this._logger.logMethodArgs?.('_notify', data);
27
+ this._$data = data;
28
+ setTimeout(() => this._$dispatch(data), 0);
29
+ }
30
+ /**
31
+ * Execute all observers callback.
32
+ */
33
+ _$dispatch(data) {
34
+ const removeList = [];
35
+ for (const listener of this._$observers) {
36
+ if (listener.options.disabled)
37
+ continue;
38
+ if (listener.options.once)
39
+ removeList.push(listener);
40
+ try {
41
+ const ret = listener.callback.call(this, data);
42
+ if (ret instanceof Promise) {
43
+ ret.catch((err) => this._logger.error('_$dispatch', 'call_listener_failed', err));
44
+ }
45
+ }
46
+ catch (err) {
47
+ this._logger.error('_$dispatch', 'call_listener_failed', err);
48
+ }
49
+ }
50
+ for (const listener of removeList) {
51
+ this.unsubscribe(listener.callback);
52
+ }
53
+ }
54
+ /**
55
+ * Subscribe to context changes.
56
+ */
57
+ subscribe(listenerCallback, options = {}) {
58
+ this._logger.logMethodArgs?.('subscribe', { options });
59
+ const _listenerObject = {
60
+ callback: listenerCallback,
61
+ options,
62
+ };
63
+ let callbackExecuted = false;
64
+ const data = this._$data;
65
+ if (data !== undefined && options.receivePrevious === true && options.disabled !== true) {
66
+ // Run callback for old dispatch signal
67
+ callbackExecuted = true;
68
+ setTimeout(() => {
69
+ try {
70
+ const ret = listenerCallback.call(this, data);
71
+ if (ret instanceof Promise) {
72
+ ret.catch((err) => this._logger.error('subscribe.receivePrevious', 'call_signal_callback_failed', err));
73
+ }
74
+ }
75
+ catch (err) {
76
+ this._logger.error('subscribe.receivePrevious', 'call_signal_callback_failed', err);
77
+ }
78
+ }, 0);
79
+ }
80
+ // If once then must remove listener after first callback called! then why push it to listenerList?!
81
+ if (options.once !== true || callbackExecuted === true) {
82
+ if (options.priority === true) {
83
+ this._$observers.unshift(_listenerObject);
84
+ }
85
+ else {
86
+ this._$observers.push(_listenerObject);
87
+ }
88
+ }
89
+ return {
90
+ unsubscribe: this.unsubscribe.bind(this, listenerCallback),
91
+ };
92
+ }
93
+ /**
94
+ * Unsubscribe from context.
95
+ */
96
+ unsubscribe(listenerCallback) {
97
+ this._logger.logMethod?.('unsubscribe');
98
+ const listenerIndex = this._$observers.findIndex((listener) => listener.callback === listenerCallback);
99
+ if (listenerIndex !== -1) {
100
+ void this._$observers.splice(listenerIndex, 1);
101
+ }
102
+ }
103
+ /**
104
+ * Clear current data without notify subscribers.
105
+ *
106
+ * `receivePrevious` in new subscribers not work until new a notify changes the data.
107
+ */
108
+ _clear() {
109
+ this._logger.logMethod?.('_clear');
110
+ this._$data = undefined;
111
+ }
112
+ /**
113
+ * Get the data of next notify.
114
+ */
115
+ _untilNewNotify() {
116
+ this._logger.logMethod?.('_untilNewNotify');
117
+ return new Promise((resolve) => {
118
+ this.subscribe(resolve, {
119
+ once: true,
120
+ priority: true,
121
+ receivePrevious: false,
122
+ });
123
+ });
124
+ }
125
+ }
126
+ //# sourceMappingURL=observable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observable.js","sourceRoot":"","sources":["src/observable.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C,iBAAiB,CAAC,CAAC;QAC5C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE;gBACtB,IAAI,EAAE,IAAI;gBACV,QAAQ,EAAE,IAAI;gBACd,eAAe,EAAE,KAAK;aACvB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import {createLogger} from '@alwatr/logger';\n\nimport type {\n SubscribeOptions,\n ListenerCallback,\n Observer,\n SubscribeResult,\n AlwatrObservableInterface,\n} from './type.js';\n\n/**\n * Alwatr base signal.\n */\nexport abstract class AlwatrObservable<T> implements AlwatrObservableInterface<T> {\n protected _name;\n protected _logger;\n protected _$data?: T;\n protected _$observers: Observer<this, T>[] = [];\n\n constructor(config: {name: string; loggerPrefix?: string}) {\n config.loggerPrefix ??= 'signal';\n this._name = config.name;\n this._logger = createLogger(`{${config.loggerPrefix}: ${this._name}}`);\n this._logger.logMethod?.('constructor');\n }\n\n /**\n * Get data.\n *\n * Return undefined if signal not notify before or expired.\n */\n protected _getData(): T | undefined {\n this._logger.logMethodFull?.('_getData', {}, this._$data);\n return this._$data;\n }\n\n /**\n * Execute all observers and remember data.\n */\n protected _notify(data: T): void {\n this._logger.logMethodArgs?.('_notify', data);\n this._$data = data;\n setTimeout(() => this._$dispatch(data), 0);\n }\n\n /**\n * Execute all observers callback.\n */\n protected _$dispatch(data: T): void {\n const removeList: Observer<this, T>[] = [];\n\n for (const listener of this._$observers) {\n if (listener.options.disabled) continue;\n if (listener.options.once) removeList.push(listener);\n\n try {\n const ret = listener.callback.call(this, data);\n if (ret instanceof Promise) {\n ret.catch((err) => this._logger.error('_$dispatch', 'call_listener_failed', err));\n }\n }\n catch (err) {\n this._logger.error('_$dispatch', 'call_listener_failed', err);\n }\n }\n\n for (const listener of removeList) {\n this.unsubscribe(listener.callback);\n }\n }\n\n /**\n * Subscribe to context changes.\n */\n subscribe(listenerCallback: ListenerCallback<this, T>, options: SubscribeOptions = {}): SubscribeResult {\n this._logger.logMethodArgs?.('subscribe', {options});\n\n const _listenerObject: Observer<this, T> = {\n callback: listenerCallback,\n options,\n };\n\n let callbackExecuted = false;\n const data = this._$data;\n if (data !== undefined && options.receivePrevious === true && options.disabled !== true) {\n // Run callback for old dispatch signal\n callbackExecuted = true;\n setTimeout(() => {\n try {\n const ret = listenerCallback.call(this, data);\n if (ret instanceof Promise) {\n ret.catch((err) => this._logger.error('subscribe.receivePrevious', 'call_signal_callback_failed', err));\n }\n }\n catch (err) {\n this._logger.error('subscribe.receivePrevious', 'call_signal_callback_failed', err);\n }\n }, 0);\n }\n\n // If once then must remove listener after first callback called! then why push it to listenerList?!\n if (options.once !== true || callbackExecuted === true) {\n if (options.priority === true) {\n this._$observers.unshift(_listenerObject);\n }\n else {\n this._$observers.push(_listenerObject);\n }\n }\n\n return {\n unsubscribe: this.unsubscribe.bind(this, listenerCallback),\n };\n }\n\n /**\n * Unsubscribe from context.\n */\n unsubscribe(listenerCallback: ListenerCallback<this, T>): void {\n this._logger.logMethod?.('unsubscribe');\n const listenerIndex = this._$observers.findIndex((listener) => listener.callback === listenerCallback);\n if (listenerIndex !== -1) {\n void this._$observers.splice(listenerIndex, 1);\n }\n }\n\n /**\n * Clear current data without notify subscribers.\n *\n * `receivePrevious` in new subscribers not work until new a notify changes the data.\n */\n protected _clear(): void {\n this._logger.logMethod?.('_clear');\n this._$data = undefined;\n }\n\n /**\n * Get the data of next notify.\n */\n protected _untilNewNotify(): Promise<T> {\n this._logger.logMethod?.('_untilNewNotify');\n return new Promise((resolve) => {\n this.subscribe(resolve, {\n once: true,\n priority: true,\n receivePrevious: false,\n });\n });\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alwatr/signal",
3
- "version": "1.1.2",
3
+ "version": "2.0.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",
@@ -21,18 +21,18 @@
21
21
  },
22
22
  "repository": {
23
23
  "type": "git",
24
- "url": "https://github.com/AliMD/alwatr",
25
- "directory": "core/signal"
24
+ "url": "https://github.com/AliMD/alwatr-signal",
25
+ "directory": "packages/signal"
26
26
  },
27
- "homepage": "https://github.com/AliMD/alwatr/tree/main/core/signal#readme",
27
+ "homepage": "https://github.com/AliMD/alwatr-signal/tree/next/packages/signal#readme",
28
28
  "bugs": {
29
- "url": "https://github.com/AliMD/alwatr/issues"
29
+ "url": "https://github.com/AliMD/alwatr-signal/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@alwatr/logger": "^1.1.2",
33
- "@alwatr/type": "^1.1.1",
34
- "@alwatr/util": "^1.2.0",
32
+ "@alwatr/logger": "^1.1.5",
33
+ "@alwatr/type": "^1.1.4",
34
+ "@alwatr/util": "^1.2.3",
35
35
  "tslib": "^2.6.2"
36
36
  },
37
- "gitHead": "16036de8a6d781116e8c463ba41a2cb8cdc34edc"
37
+ "gitHead": "1196deebb143a163b2a4b520ff3bb60bfd5399c4"
38
38
  }
package/signal.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { AlwatrObservable } from './observable.js';
2
+ /**
3
+ * Alwatr event signal.
4
+ */
5
+ export declare class AlwatrSignal<T> extends AlwatrObservable<T> {
6
+ constructor(config: {
7
+ name: string;
8
+ loggerPrefix?: string;
9
+ });
10
+ /**
11
+ * Dispatch an event to all listeners.
12
+ */
13
+ notify(detail: T): void;
14
+ /**
15
+ * Wait until next event.
16
+ */
17
+ untilNewNotify(): Promise<T>;
18
+ }
19
+ //# sourceMappingURL=signal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["src/signal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAEjD;;GAEG;AACH,qBAAa,YAAY,CAAC,CAAC,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAC;gBAC1C,MAAM,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAC;IAKzD;;OAEG;IACH,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI;IAIvB;;OAEG;IACH,cAAc,IAAI,OAAO,CAAC,CAAC,CAAC;CAG7B"}
package/signal.js ADDED
@@ -0,0 +1,23 @@
1
+ import { AlwatrObservable } from './observable.js';
2
+ /**
3
+ * Alwatr event signal.
4
+ */
5
+ export class AlwatrSignal extends AlwatrObservable {
6
+ constructor(config) {
7
+ config.loggerPrefix ?? (config.loggerPrefix = 'signal');
8
+ super(config);
9
+ }
10
+ /**
11
+ * Dispatch an event to all listeners.
12
+ */
13
+ notify(detail) {
14
+ this._notify(detail);
15
+ }
16
+ /**
17
+ * Wait until next event.
18
+ */
19
+ untilNewNotify() {
20
+ return super._untilNewNotify();
21
+ }
22
+ }
23
+ //# sourceMappingURL=signal.js.map
package/signal.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signal.js","sourceRoot":"","sources":["src/signal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAEjD;;GAEG;AACH,MAAM,OAAO,YAAgB,SAAQ,gBAAmB;IACtD,YAAY,MAA6C;QACvD,MAAM,CAAC,YAAY,KAAnB,MAAM,CAAC,YAAY,GAAK,QAAQ,EAAC;QACjC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAS;QACd,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,KAAK,CAAC,eAAe,EAAE,CAAC;IACjC,CAAC;CACF","sourcesContent":["import {AlwatrObservable} from './observable.js';\n\n/**\n * Alwatr event signal.\n */\nexport class AlwatrSignal<T> extends AlwatrObservable<T> {\n constructor(config: {name: string; loggerPrefix?: string}) {\n config.loggerPrefix ??= 'signal';\n super(config);\n }\n\n /**\n * Dispatch an event to all listeners.\n */\n notify(detail: T): void {\n this._notify(detail);\n }\n\n /**\n * Wait until next event.\n */\n untilNewNotify(): Promise<T> {\n return super._untilNewNotify();\n }\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import { AlwatrObservable } from './observable.js';
2
+ /**
3
+ * Alwatr event signal without any data.
4
+ */
5
+ export declare class AlwatrSimpleSignal extends AlwatrObservable<undefined> {
6
+ constructor(config: {
7
+ name: string;
8
+ loggerPrefix?: string;
9
+ });
10
+ /**
11
+ * Dispatch an event to all listeners.
12
+ */
13
+ notify(): void;
14
+ /**
15
+ * Wait until next event signal.
16
+ */
17
+ untilNewNotify(): Promise<void>;
18
+ }
19
+ //# sourceMappingURL=simple-signal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simple-signal.d.ts","sourceRoot":"","sources":["src/simple-signal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAEjD;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,gBAAgB,CAAC,SAAS,CAAC;gBACrD,MAAM,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAC;IAKzD;;OAEG;IACH,MAAM,IAAI,IAAI;IAId;;OAEG;IACH,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;CAGhC"}
@@ -0,0 +1,23 @@
1
+ import { AlwatrObservable } from './observable.js';
2
+ /**
3
+ * Alwatr event signal without any data.
4
+ */
5
+ export class AlwatrSimpleSignal extends AlwatrObservable {
6
+ constructor(config) {
7
+ config.loggerPrefix ?? (config.loggerPrefix = 'signal');
8
+ super(config);
9
+ }
10
+ /**
11
+ * Dispatch an event to all listeners.
12
+ */
13
+ notify() {
14
+ this._notify(undefined);
15
+ }
16
+ /**
17
+ * Wait until next event signal.
18
+ */
19
+ untilNewNotify() {
20
+ return super._untilNewNotify();
21
+ }
22
+ }
23
+ //# sourceMappingURL=simple-signal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simple-signal.js","sourceRoot":"","sources":["src/simple-signal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAEjD;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,gBAA2B;IACjE,YAAY,MAA6C;QACvD,MAAM,CAAC,YAAY,KAAnB,MAAM,CAAC,YAAY,GAAK,QAAQ,EAAC;QACjC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,KAAK,CAAC,eAAe,EAAE,CAAC;IACjC,CAAC;CACF","sourcesContent":["import {AlwatrObservable} from './observable.js';\n\n/**\n * Alwatr event signal without any data.\n */\nexport class AlwatrSimpleSignal extends AlwatrObservable<undefined> {\n constructor(config: {name: string; loggerPrefix?: string}) {\n config.loggerPrefix ??= 'signal';\n super(config);\n }\n\n /**\n * Dispatch an event to all listeners.\n */\n notify(): void {\n this._notify(undefined);\n }\n\n /**\n * Wait until next event signal.\n */\n untilNewNotify(): Promise<void> {\n return super._untilNewNotify();\n }\n}\n"]}