@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.
- package/CHANGELOG.md +173 -163
- package/context.d.ts +31 -0
- package/context.d.ts.map +1 -0
- package/context.js +40 -0
- package/context.js.map +1 -0
- package/index.d.ts +5 -9
- package/index.d.ts.map +1 -1
- package/index.js +10 -16
- package/index.js.map +1 -1
- package/multithread-context.d.ts +21 -0
- package/multithread-context.d.ts.map +1 -0
- package/multithread-context.js +50 -0
- package/multithread-context.js.map +1 -0
- package/observable.d.ts +47 -0
- package/observable.d.ts.map +1 -0
- package/observable.js +126 -0
- package/observable.js.map +1 -0
- package/package.json +9 -9
- package/signal.d.ts +19 -0
- package/signal.d.ts.map +1 -0
- package/signal.js +23 -0
- package/signal.js.map +1 -0
- package/simple-signal.d.ts +19 -0
- package/simple-signal.d.ts.map +1 -0
- package/simple-signal.js +23 -0
- package/simple-signal.js.map +1 -0
- package/type.d.ts +15 -126
- package/type.d.ts.map +1 -1
- package/type.js.map +1 -1
- package/command-handler.d.ts +0 -25
- package/command-handler.d.ts.map +0 -1
- package/command-handler.js +0 -24
- package/command-handler.js.map +0 -1
- package/command-trigger.d.ts +0 -64
- package/command-trigger.d.ts.map +0 -1
- package/command-trigger.js +0 -64
- package/command-trigger.js.map +0 -1
- package/context-consumer.d.ts +0 -124
- package/context-consumer.d.ts.map +0 -1
- package/context-consumer.js +0 -124
- package/context-consumer.js.map +0 -1
- package/context-provider.d.ts +0 -120
- package/context-provider.d.ts.map +0 -1
- package/context-provider.js +0 -120
- package/context-provider.js.map +0 -1
- package/core.d.ts +0 -181
- package/core.d.ts.map +0 -1
- package/core.js +0 -388
- package/core.js.map +0 -1
- package/event-listener.d.ts +0 -120
- package/event-listener.d.ts.map +0 -1
- package/event-listener.js +0 -120
- package/event-listener.js.map +0 -1
- package/event-trigger.d.ts +0 -76
- package/event-trigger.d.ts.map +0 -1
- package/event-trigger.js +0 -76
- package/event-trigger.js.map +0 -1
- package/requestable-context-consumer.d.ts +0 -60
- package/requestable-context-consumer.d.ts.map +0 -1
- package/requestable-context-consumer.js +0 -54
- package/requestable-context-consumer.js.map +0 -1
- package/requestable-context-provider.d.ts +0 -69
- package/requestable-context-provider.d.ts.map +0 -1
- package/requestable-context-provider.js +0 -63
- package/requestable-context-provider.js.map +0 -1
package/type.d.ts
CHANGED
|
@@ -1,146 +1,35 @@
|
|
|
1
|
-
import type { MaybePromise
|
|
2
|
-
export type DebounceType = 'No' | 'NextCycle' | 'AnimationFrame' | 'Timeout';
|
|
1
|
+
import type { MaybePromise } from '@alwatr/type';
|
|
3
2
|
/**
|
|
4
3
|
* Subscribe options type.
|
|
5
4
|
*/
|
|
6
5
|
export interface SubscribeOptions {
|
|
7
6
|
/**
|
|
8
7
|
* If true, the listener will be called only once.
|
|
9
|
-
* @default false
|
|
10
8
|
*/
|
|
11
|
-
once
|
|
9
|
+
once?: true;
|
|
12
10
|
/**
|
|
13
11
|
* If true, the listener will be called before other.
|
|
14
|
-
* @default false
|
|
15
12
|
*/
|
|
16
|
-
priority
|
|
13
|
+
priority?: true;
|
|
17
14
|
/**
|
|
18
15
|
* If true, the listener will be defined disabled by default.
|
|
19
|
-
*
|
|
20
|
-
* @default false
|
|
21
16
|
*/
|
|
22
|
-
disabled
|
|
17
|
+
disabled?: true;
|
|
23
18
|
/**
|
|
24
|
-
*
|
|
25
|
-
* If Immediate, the listener will be called immediately without any debounce for preview signal.
|
|
26
|
-
*
|
|
27
|
-
* @default `NextCycle`
|
|
19
|
+
* If true, calls the listener (callback) with previous signal value (if dispatched before).
|
|
28
20
|
*/
|
|
29
|
-
receivePrevious
|
|
21
|
+
receivePrevious?: boolean;
|
|
30
22
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/**
|
|
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.
|
|
41
|
-
*
|
|
42
|
-
* @default `AnimationFrame`
|
|
43
|
-
*/
|
|
44
|
-
debounce: DebounceType;
|
|
23
|
+
export type ListenerCallback<T, D> = (this: T, detail: D) => MaybePromise<void>;
|
|
24
|
+
export interface Observer<T, D> {
|
|
25
|
+
callback: ListenerCallback<T, D>;
|
|
26
|
+
options: SubscribeOptions;
|
|
45
27
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*/
|
|
49
|
-
export interface ProviderOptions {
|
|
50
|
-
/**
|
|
51
|
-
* Calling signal provider (request signal callback) with preview signal value (if dispatched before).
|
|
52
|
-
* If Immediate, the listener will be called immediately without any debounce for preview signal.
|
|
53
|
-
*
|
|
54
|
-
* @default `NextCycle`
|
|
55
|
-
*/
|
|
56
|
-
receivePrevious: DebounceType;
|
|
57
|
-
/**
|
|
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.
|
|
63
|
-
*
|
|
64
|
-
* @default `AnimationFrame`
|
|
65
|
-
*/
|
|
66
|
-
debounce: DebounceType;
|
|
28
|
+
export interface SubscribeResult {
|
|
29
|
+
unsubscribe: () => void;
|
|
67
30
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
export type ListenerFunction<T extends Stringifyable> = (detail: T) => void | Promise<void>;
|
|
72
|
-
/**
|
|
73
|
-
* Command/Context provider/handler function.
|
|
74
|
-
*/
|
|
75
|
-
export type ProviderFunction<TArgument, TReturn> = (argumentObject: TArgument) => MaybePromise<TReturn>;
|
|
76
|
-
/**
|
|
77
|
-
* Listener spec.
|
|
78
|
-
*/
|
|
79
|
-
export interface ListenerSpec {
|
|
80
|
-
/**
|
|
81
|
-
* Unique listener id
|
|
82
|
-
*/
|
|
83
|
-
id: number;
|
|
84
|
-
/**
|
|
85
|
-
* Signal id
|
|
86
|
-
*/
|
|
87
|
-
signalId: string;
|
|
31
|
+
export interface AlwatrObservableInterface<T> {
|
|
32
|
+
subscribe(listenerCallback: ListenerCallback<this, T>, options?: SubscribeOptions): SubscribeResult;
|
|
33
|
+
unsubscribe(listenerCallback: ListenerCallback<this, T>): void;
|
|
88
34
|
}
|
|
89
|
-
/**
|
|
90
|
-
* Signal listeners object in storage.
|
|
91
|
-
*/
|
|
92
|
-
export type ListenerObject<T extends Stringifyable> = ListenerSpec & {
|
|
93
|
-
/**
|
|
94
|
-
* If true, the listener will be called only once and removed automatically after first call
|
|
95
|
-
*/
|
|
96
|
-
once: boolean;
|
|
97
|
-
/**
|
|
98
|
-
* If true, the listener will be disabled.
|
|
99
|
-
*/
|
|
100
|
-
disabled: boolean;
|
|
101
|
-
callback: ListenerFunction<T>;
|
|
102
|
-
};
|
|
103
|
-
/**
|
|
104
|
-
* Signal object in storage.
|
|
105
|
-
*/
|
|
106
|
-
export interface SignalObject<T extends Stringifyable> {
|
|
107
|
-
/**
|
|
108
|
-
* Signal id for direct access.
|
|
109
|
-
*/
|
|
110
|
-
id: string;
|
|
111
|
-
/**
|
|
112
|
-
* Last dispatched detail.
|
|
113
|
-
*/
|
|
114
|
-
detail?: T;
|
|
115
|
-
/**
|
|
116
|
-
* If true, the signal is disabled.
|
|
117
|
-
*/
|
|
118
|
-
disabled: boolean;
|
|
119
|
-
/**
|
|
120
|
-
* Dispatches debounced (delayed).
|
|
121
|
-
* Internal use case for debounce dispatch signal.
|
|
122
|
-
*/
|
|
123
|
-
debounced: boolean;
|
|
124
|
-
/**
|
|
125
|
-
* Signal listeners list.
|
|
126
|
-
*/
|
|
127
|
-
listenerList: ListenerObject<T>[];
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Signal stack storage.
|
|
131
|
-
*/
|
|
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
|
-
};
|
|
146
35
|
//# 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,KAAK,EAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC;IAEZ;;OAEG;IACH,QAAQ,CAAC,EAAE,IAAI,CAAC;IAEhB;;OAEG;IACH,QAAQ,CAAC,EAAE,IAAI,CAAC;IAEhB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAM3B;AAED,MAAM,MAAM,gBAAgB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;AAEhF,MAAM,WAAW,QAAQ,CAAC,CAAC,EAAE,CAAC;IAC5B,QAAQ,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACjC,OAAO,EAAE,gBAAgB,CAAC;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB;AAED,MAAM,WAAW,yBAAyB,CAAC,CAAC;IAC1C,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,eAAe,CAAC;IACpG,WAAW,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC;CAChE"}
|
package/type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":"","sourcesContent":["import type {MaybePromise
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":"","sourcesContent":["import type {MaybePromise} from '@alwatr/type';\n\n/**\n * Subscribe options type.\n */\nexport interface SubscribeOptions {\n /**\n * If true, the listener will be called only once.\n */\n once?: true;\n\n /**\n * If true, the listener will be called before other.\n */\n priority?: true;\n\n /**\n * If true, the listener will be defined disabled by default.\n */\n disabled?: true;\n\n /**\n * If true, calls the listener (callback) with previous signal value (if dispatched before).\n */\n receivePrevious?: boolean;\n\n /**\n * If defined, calls the listener (callback) with debounce.\n */\n // debounce?: 'AnimationFrame' | number;\n}\n\nexport type ListenerCallback<T, D> = (this: T, detail: D) => MaybePromise<void>;\n\nexport interface Observer<T, D> {\n callback: ListenerCallback<T, D>;\n options: SubscribeOptions;\n}\n\nexport interface SubscribeResult {\n unsubscribe: () => void;\n}\n\nexport interface AlwatrObservableInterface<T> {\n subscribe(listenerCallback: ListenerCallback<this, T>, options?: SubscribeOptions): SubscribeResult;\n unsubscribe(listenerCallback: ListenerCallback<this, T>): void;\n}\n"]}
|
package/command-handler.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Command handler/define interface.
|
|
3
|
-
*/
|
|
4
|
-
export declare const commandHandler: {
|
|
5
|
-
/**
|
|
6
|
-
* Defines the command and dispatch returned value.
|
|
7
|
-
*
|
|
8
|
-
* Subscribe commandFunction to request-command-signal and dispatch callback-signal with commandFunction return value.
|
|
9
|
-
*
|
|
10
|
-
* Example:
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* commandHandler.define<TArgument, TReturn>(
|
|
14
|
-
* 'show-prompt',
|
|
15
|
-
* async (argumentObject) => {
|
|
16
|
-
* return await showPrompt(argumentObject);
|
|
17
|
-
* },
|
|
18
|
-
* );
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
readonly define: <TArgument extends import("@alwatr/type").StringifyableRecord, TReturn extends import("@alwatr/type").Stringifyable>(signalId: string, signalProvider: import("./type.js").ProviderFunction<TArgument & {
|
|
22
|
-
_callbackSignalId?: string | undefined;
|
|
23
|
-
}, TReturn>, options?: Partial<Pick<import("./type.js").ProviderOptions, "debounce">>) => import("./type.js").ListenerSpec;
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=command-handler.d.ts.map
|
package/command-handler.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command-handler.d.ts","sourceRoot":"","sources":["src/command-handler.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,cAAc;IACzB;;;;;;;;;;;;;;;OAeG;;;;CAEK,CAAC"}
|
package/command-handler.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from './core.js';
|
|
2
|
-
/**
|
|
3
|
-
* Command handler/define interface.
|
|
4
|
-
*/
|
|
5
|
-
export const commandHandler = {
|
|
6
|
-
/**
|
|
7
|
-
* Defines the command and dispatch returned value.
|
|
8
|
-
*
|
|
9
|
-
* Subscribe commandFunction to request-command-signal and dispatch callback-signal with commandFunction return value.
|
|
10
|
-
*
|
|
11
|
-
* Example:
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* commandHandler.define<TArgument, TReturn>(
|
|
15
|
-
* 'show-prompt',
|
|
16
|
-
* async (argumentObject) => {
|
|
17
|
-
* return await showPrompt(argumentObject);
|
|
18
|
-
* },
|
|
19
|
-
* );
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
define: defineCommand,
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=command-handler.js.map
|
package/command-handler.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command-handler.js","sourceRoot":"","sources":["src/command-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,WAAW,CAAC;AAExC;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B;;;;;;;;;;;;;;;OAeG;IACH,MAAM,EAAE,aAAa;CACb,CAAC","sourcesContent":["import {defineCommand} from './core.js';\n\n/**\n * Command handler/define interface.\n */\nexport const commandHandler = {\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 * commandHandler.define<TArgument, TReturn>(\n * 'show-prompt',\n * async (argumentObject) => {\n * return await showPrompt(argumentObject);\n * },\n * );\n * ```\n */\n define: defineCommand,\n} as const;\n"]}
|
package/command-trigger.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { Stringifyable, StringifyableRecord } from '@alwatr/type';
|
|
2
|
-
/**
|
|
3
|
-
* Command trigger/request interface.
|
|
4
|
-
*/
|
|
5
|
-
export declare const commandTrigger: {
|
|
6
|
-
/**
|
|
7
|
-
* Dispatch request command signal with commandArgument as detail.
|
|
8
|
-
*
|
|
9
|
-
* Example:
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* commandTrigger.request<ArgumentType>('show-dialog', {foo: 'bar'});
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
readonly request: <TArgument extends StringifyableRecord>(commandId: string, commandArgument: TArgument) => void;
|
|
16
|
-
/**
|
|
17
|
-
* Dispatch request command signal with commandArgument as detail and return untilNext of callback signal.
|
|
18
|
-
*
|
|
19
|
-
* Request command and wait for answer.
|
|
20
|
-
*
|
|
21
|
-
* Example:
|
|
22
|
-
*
|
|
23
|
-
* ```ts
|
|
24
|
-
* const response = await commandTrigger.requestWithResponse<ArgumentType, ReturnType>('show-dialog', {foo: 'bar'});
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
readonly requestWithResponse: <TArgument_1 extends StringifyableRecord, TReturn extends Stringifyable>(commandId: string, commandArgument: TArgument_1) => Promise<TReturn>;
|
|
28
|
-
/**
|
|
29
|
-
* Bind define command to special command.
|
|
30
|
-
*
|
|
31
|
-
* Example:
|
|
32
|
-
*
|
|
33
|
-
* ```ts
|
|
34
|
-
* const showDialog = commandTrigger.bind<ArgumentType, ReturnType>('show-dialog');
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
readonly bind: <TArgument_2 extends StringifyableRecord, TReturn_1 extends Stringifyable>(commandId: string) => {
|
|
38
|
-
/**
|
|
39
|
-
* Command signal Id.
|
|
40
|
-
*/
|
|
41
|
-
id: string;
|
|
42
|
-
/**
|
|
43
|
-
* Dispatch request command signal with commandArgument as detail and return untilNext of callback signal.
|
|
44
|
-
*
|
|
45
|
-
* Example:
|
|
46
|
-
*
|
|
47
|
-
* ```ts
|
|
48
|
-
* showDialog.request({foo: 'bar'});
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
request: (commandArgument: TArgument_2) => void;
|
|
52
|
-
/**
|
|
53
|
-
* Dispatch request command signal with commandArgument as detail and return untilNext of callback signal.
|
|
54
|
-
*
|
|
55
|
-
* Example:
|
|
56
|
-
*
|
|
57
|
-
* ```ts
|
|
58
|
-
* const response = await showDialog.requestWithResponse({foo: 'bar'});
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
requestWithResponse: (commandArgument: TArgument_2) => Promise<TReturn_1>;
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
//# sourceMappingURL=command-trigger.d.ts.map
|
package/command-trigger.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command-trigger.d.ts","sourceRoot":"","sources":["src/command-trigger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAiB,aAAa,EAAE,mBAAmB,EAAC,MAAM,cAAc,CAAC;AAErF;;GAEG;AACH,eAAO,MAAM,cAAc;IACzB;;;;;;;;OAQG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;OAQG;yGACqF,MAAM;QAC5F;;WAEG;;QAGH;;;;;;;;WAQG;;QAIH;;;;;;;;WAQG;;;CAIG,CAAC"}
|
package/command-trigger.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { requestCommand, requestCommandWithResponse } from './core.js';
|
|
2
|
-
/**
|
|
3
|
-
* Command trigger/request interface.
|
|
4
|
-
*/
|
|
5
|
-
export const commandTrigger = {
|
|
6
|
-
/**
|
|
7
|
-
* Dispatch request command signal with commandArgument as detail.
|
|
8
|
-
*
|
|
9
|
-
* Example:
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* commandTrigger.request<ArgumentType>('show-dialog', {foo: 'bar'});
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
request: requestCommand,
|
|
16
|
-
/**
|
|
17
|
-
* Dispatch request command signal with commandArgument as detail and return untilNext of callback signal.
|
|
18
|
-
*
|
|
19
|
-
* Request command and wait for answer.
|
|
20
|
-
*
|
|
21
|
-
* Example:
|
|
22
|
-
*
|
|
23
|
-
* ```ts
|
|
24
|
-
* const response = await commandTrigger.requestWithResponse<ArgumentType, ReturnType>('show-dialog', {foo: 'bar'});
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
requestWithResponse: requestCommandWithResponse,
|
|
28
|
-
/**
|
|
29
|
-
* Bind define command to special command.
|
|
30
|
-
*
|
|
31
|
-
* Example:
|
|
32
|
-
*
|
|
33
|
-
* ```ts
|
|
34
|
-
* const showDialog = commandTrigger.bind<ArgumentType, ReturnType>('show-dialog');
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
bind: (commandId) => ({
|
|
38
|
-
/**
|
|
39
|
-
* Command signal Id.
|
|
40
|
-
*/
|
|
41
|
-
id: commandId,
|
|
42
|
-
/**
|
|
43
|
-
* Dispatch request command signal with commandArgument as detail and return untilNext of callback signal.
|
|
44
|
-
*
|
|
45
|
-
* Example:
|
|
46
|
-
*
|
|
47
|
-
* ```ts
|
|
48
|
-
* showDialog.request({foo: 'bar'});
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
request: requestCommand.bind(null, commandId),
|
|
52
|
-
/**
|
|
53
|
-
* Dispatch request command signal with commandArgument as detail and return untilNext of callback signal.
|
|
54
|
-
*
|
|
55
|
-
* Example:
|
|
56
|
-
*
|
|
57
|
-
* ```ts
|
|
58
|
-
* const response = await showDialog.requestWithResponse({foo: 'bar'});
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
requestWithResponse: requestCommandWithResponse.bind(null, commandId),
|
|
62
|
-
}),
|
|
63
|
-
};
|
|
64
|
-
//# sourceMappingURL=command-trigger.js.map
|
package/command-trigger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command-trigger.js","sourceRoot":"","sources":["src/command-trigger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAE,0BAA0B,EAAC,MAAM,WAAW,CAAC;AAIrE;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B;;;;;;;;OAQG;IACH,OAAO,EAAE,cAAc;IAEvB;;;;;;;;;;OAUG;IACH,mBAAmB,EAAE,0BAA0B;IAE/C;;;;;;;;OAQG;IACH,IAAI,EAAE,CAAuE,SAAiB,EAAE,EAAE,CAAA,CAAC;QACjG;;WAEG;QACH,EAAE,EAAE,SAAS;QAEb;;;;;;;;WAQG;QACH,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CACM;QAElD;;;;;;;;WAQG;QACH,mBAAmB,EAAE,0BAA0B,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CACG;KACxE,CAAC;CACM,CAAC","sourcesContent":["import {requestCommand, requestCommandWithResponse} from './core.js';\n\nimport type {OmitFirstParam, Stringifyable, StringifyableRecord} from '@alwatr/type';\n\n/**\n * Command trigger/request interface.\n */\nexport const commandTrigger = {\n /**\n * Dispatch request command signal with commandArgument as detail.\n *\n * Example:\n *\n * ```ts\n * commandTrigger.request<ArgumentType>('show-dialog', {foo: 'bar'});\n * ```\n */\n request: requestCommand,\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 commandTrigger.requestWithResponse<ArgumentType, ReturnType>('show-dialog', {foo: 'bar'});\n * ```\n */\n requestWithResponse: requestCommandWithResponse,\n\n /**\n * Bind define command to special command.\n *\n * Example:\n *\n * ```ts\n * const showDialog = commandTrigger.bind<ArgumentType, ReturnType>('show-dialog');\n * ```\n */\n bind: <TArgument extends StringifyableRecord, TReturn extends Stringifyable>(commandId: string) =>({\n /**\n * Command signal Id.\n */\n id: commandId,\n\n /**\n * Dispatch request command signal with commandArgument as detail and return untilNext of callback signal.\n *\n * Example:\n *\n * ```ts\n * showDialog.request({foo: 'bar'});\n * ```\n */\n request: requestCommand.bind(null, commandId) as unknown as\n OmitFirstParam<typeof requestCommand<TArgument>>,\n\n /**\n * Dispatch request command signal with commandArgument as detail and return untilNext of callback signal.\n *\n * Example:\n *\n * ```ts\n * const response = await showDialog.requestWithResponse({foo: 'bar'});\n * ```\n */\n requestWithResponse: requestCommandWithResponse.bind(null, commandId) as unknown as\n OmitFirstParam<typeof requestCommandWithResponse<TArgument, TReturn>>,\n }),\n} as const;\n"]}
|
package/context-consumer.d.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import type { Stringifyable } from '@alwatr/type';
|
|
2
|
-
/**
|
|
3
|
-
* Context consumer interface.
|
|
4
|
-
*/
|
|
5
|
-
export declare const contextConsumer: {
|
|
6
|
-
/**
|
|
7
|
-
* Get context value.
|
|
8
|
-
*
|
|
9
|
-
* Return undefined if context not set before or expired.
|
|
10
|
-
*
|
|
11
|
-
* Example:
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* const currentProductList = contextConsumer.getValue<ProductListType>('product-list');
|
|
15
|
-
* if (currentProductList === undefined) {
|
|
16
|
-
* // productList not set before or expired.
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
readonly getValue: <T extends Stringifyable>(signalId: string) => T | undefined;
|
|
21
|
-
/**
|
|
22
|
-
* Waits until the context value changes.
|
|
23
|
-
*
|
|
24
|
-
* Example:
|
|
25
|
-
*
|
|
26
|
-
* ```ts
|
|
27
|
-
* const newProductList = await contextConsumer.untilChange<ProductListType>('product-list');
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
readonly untilChange: <T_1 extends Stringifyable>(signalId: string) => Promise<T_1>;
|
|
31
|
-
/**
|
|
32
|
-
* Subscribe to context changes, work like addEventListener.
|
|
33
|
-
*
|
|
34
|
-
* Example:
|
|
35
|
-
*
|
|
36
|
-
* ```ts
|
|
37
|
-
* const listener = contextConsumer.subscribe<ProductListType>('product-list', (productList) => {
|
|
38
|
-
* console.log(productList);
|
|
39
|
-
* });
|
|
40
|
-
* // ...
|
|
41
|
-
* contextConsumer.unsubscribe(listener);
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
readonly subscribe: <T_2 extends Stringifyable>(signalId: string, listenerCallback: import("./type.js").ListenerFunction<T_2>, options?: Partial<import("./type.js").SubscribeOptions>) => import("./type.js").ListenerSpec;
|
|
45
|
-
/**
|
|
46
|
-
* Unsubscribe from context changes, work like removeEventListener.
|
|
47
|
-
*
|
|
48
|
-
* Example:
|
|
49
|
-
*
|
|
50
|
-
* ```ts
|
|
51
|
-
* const listener = contextConsumer.subscribe<ProductListType>('product-list', (productList) => {
|
|
52
|
-
* console.log(productList);
|
|
53
|
-
* });
|
|
54
|
-
* // ...
|
|
55
|
-
* contextConsumer.unsubscribe(listener);
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
readonly unsubscribe: (listener: import("./type.js").ListenerSpec) => void;
|
|
59
|
-
/**
|
|
60
|
-
* Bind this interface to special context.
|
|
61
|
-
*
|
|
62
|
-
* Example:
|
|
63
|
-
*
|
|
64
|
-
* ```ts
|
|
65
|
-
* const productListConsumer = contextConsumer.bind<ProductListType>('product-list');
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
readonly bind: <T_3 extends Stringifyable>(contextId: string) => {
|
|
69
|
-
/**
|
|
70
|
-
* Context signal Id.
|
|
71
|
-
*/
|
|
72
|
-
readonly id: string;
|
|
73
|
-
/**
|
|
74
|
-
* Get context value.
|
|
75
|
-
*
|
|
76
|
-
* Return undefined if context not set before or expired.
|
|
77
|
-
*
|
|
78
|
-
* Example:
|
|
79
|
-
*
|
|
80
|
-
* ```ts
|
|
81
|
-
* const currentProductList = productListConsumer.getValue();
|
|
82
|
-
* if (currentProductList === undefined) {
|
|
83
|
-
* // productList not set before or expired.
|
|
84
|
-
* }
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
readonly getValue: () => T_3 | undefined;
|
|
88
|
-
/**
|
|
89
|
-
* Waits until the context value changes.
|
|
90
|
-
*
|
|
91
|
-
* Example:
|
|
92
|
-
*
|
|
93
|
-
* ```ts
|
|
94
|
-
* const newProductList = await productListConsumer.untilChange();
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
readonly untilChange: () => Promise<T_3>;
|
|
98
|
-
/**
|
|
99
|
-
* Subscribe to context changes, work like addEventListener.
|
|
100
|
-
*
|
|
101
|
-
* Example:
|
|
102
|
-
*
|
|
103
|
-
* ```ts
|
|
104
|
-
* const listener = productListConsumer.subscribe((productList) => console.log(productList));
|
|
105
|
-
* // ...
|
|
106
|
-
* productListConsumer.unsubscribe(listener);
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
readonly subscribe: (listenerCallback: import("./type.js").ListenerFunction<T_3>, options?: Partial<import("./type.js").SubscribeOptions> | undefined) => import("./type.js").ListenerSpec;
|
|
110
|
-
/**
|
|
111
|
-
* Unsubscribe from context changes, work like removeEventListener.
|
|
112
|
-
*
|
|
113
|
-
* Example:
|
|
114
|
-
*
|
|
115
|
-
* ```ts
|
|
116
|
-
* const listener = productListConsumer.subscribe((productList) => console.log(productList));
|
|
117
|
-
* // ...
|
|
118
|
-
* productListConsumer.unsubscribe(listener);
|
|
119
|
-
* ```
|
|
120
|
-
*/
|
|
121
|
-
readonly unsubscribe: (listener: import("./type.js").ListenerSpec) => void;
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
//# sourceMappingURL=context-consumer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-consumer.d.ts","sourceRoot":"","sources":["src/context-consumer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,aAAa,EAAiB,MAAM,cAAc,CAAC;AAEhE;;GAEG;AACH,eAAO,MAAM,eAAe;IAC1B;;;;;;;;;;;;;OAaG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;;;;;;OAYG;;IAGH;;;;;;;;;;;;OAYG;;IAGH;;;;;;;;OAQG;0DACwC,MAAM;QAC/C;;WAEG;;QAGH;;;;;;;;;;;;;WAaG;;QAGH;;;;;;;;WAQG;;QAGH;;;;;;;;;;WAUG;;QAIH;;;;;;;;;;WAUG;;;CAGG,CAAC"}
|
package/context-consumer.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { getDetail, subscribe, unsubscribe, untilNext } from './core.js';
|
|
2
|
-
/**
|
|
3
|
-
* Context consumer interface.
|
|
4
|
-
*/
|
|
5
|
-
export const contextConsumer = {
|
|
6
|
-
/**
|
|
7
|
-
* Get context value.
|
|
8
|
-
*
|
|
9
|
-
* Return undefined if context not set before or expired.
|
|
10
|
-
*
|
|
11
|
-
* Example:
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* const currentProductList = contextConsumer.getValue<ProductListType>('product-list');
|
|
15
|
-
* if (currentProductList === undefined) {
|
|
16
|
-
* // productList not set before or expired.
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
getValue: getDetail,
|
|
21
|
-
/**
|
|
22
|
-
* Waits until the context value changes.
|
|
23
|
-
*
|
|
24
|
-
* Example:
|
|
25
|
-
*
|
|
26
|
-
* ```ts
|
|
27
|
-
* const newProductList = await contextConsumer.untilChange<ProductListType>('product-list');
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
untilChange: untilNext,
|
|
31
|
-
/**
|
|
32
|
-
* Subscribe to context changes, work like addEventListener.
|
|
33
|
-
*
|
|
34
|
-
* Example:
|
|
35
|
-
*
|
|
36
|
-
* ```ts
|
|
37
|
-
* const listener = contextConsumer.subscribe<ProductListType>('product-list', (productList) => {
|
|
38
|
-
* console.log(productList);
|
|
39
|
-
* });
|
|
40
|
-
* // ...
|
|
41
|
-
* contextConsumer.unsubscribe(listener);
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
subscribe: subscribe,
|
|
45
|
-
/**
|
|
46
|
-
* Unsubscribe from context changes, work like removeEventListener.
|
|
47
|
-
*
|
|
48
|
-
* Example:
|
|
49
|
-
*
|
|
50
|
-
* ```ts
|
|
51
|
-
* const listener = contextConsumer.subscribe<ProductListType>('product-list', (productList) => {
|
|
52
|
-
* console.log(productList);
|
|
53
|
-
* });
|
|
54
|
-
* // ...
|
|
55
|
-
* contextConsumer.unsubscribe(listener);
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
unsubscribe: unsubscribe,
|
|
59
|
-
/**
|
|
60
|
-
* Bind this interface to special context.
|
|
61
|
-
*
|
|
62
|
-
* Example:
|
|
63
|
-
*
|
|
64
|
-
* ```ts
|
|
65
|
-
* const productListConsumer = contextConsumer.bind<ProductListType>('product-list');
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
bind: (contextId) => ({
|
|
69
|
-
/**
|
|
70
|
-
* Context signal Id.
|
|
71
|
-
*/
|
|
72
|
-
id: contextId,
|
|
73
|
-
/**
|
|
74
|
-
* Get context value.
|
|
75
|
-
*
|
|
76
|
-
* Return undefined if context not set before or expired.
|
|
77
|
-
*
|
|
78
|
-
* Example:
|
|
79
|
-
*
|
|
80
|
-
* ```ts
|
|
81
|
-
* const currentProductList = productListConsumer.getValue();
|
|
82
|
-
* if (currentProductList === undefined) {
|
|
83
|
-
* // productList not set before or expired.
|
|
84
|
-
* }
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
getValue: getDetail.bind(null, contextId),
|
|
88
|
-
/**
|
|
89
|
-
* Waits until the context value changes.
|
|
90
|
-
*
|
|
91
|
-
* Example:
|
|
92
|
-
*
|
|
93
|
-
* ```ts
|
|
94
|
-
* const newProductList = await productListConsumer.untilChange();
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
untilChange: untilNext.bind(null, contextId),
|
|
98
|
-
/**
|
|
99
|
-
* Subscribe to context changes, work like addEventListener.
|
|
100
|
-
*
|
|
101
|
-
* Example:
|
|
102
|
-
*
|
|
103
|
-
* ```ts
|
|
104
|
-
* const listener = productListConsumer.subscribe((productList) => console.log(productList));
|
|
105
|
-
* // ...
|
|
106
|
-
* productListConsumer.unsubscribe(listener);
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
subscribe: subscribe.bind(null, contextId),
|
|
110
|
-
/**
|
|
111
|
-
* Unsubscribe from context changes, work like removeEventListener.
|
|
112
|
-
*
|
|
113
|
-
* Example:
|
|
114
|
-
*
|
|
115
|
-
* ```ts
|
|
116
|
-
* const listener = productListConsumer.subscribe((productList) => console.log(productList));
|
|
117
|
-
* // ...
|
|
118
|
-
* productListConsumer.unsubscribe(listener);
|
|
119
|
-
* ```
|
|
120
|
-
*/
|
|
121
|
-
unsubscribe: unsubscribe,
|
|
122
|
-
}),
|
|
123
|
-
};
|
|
124
|
-
//# sourceMappingURL=context-consumer.js.map
|
package/context-consumer.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-consumer.js","sourceRoot":"","sources":["src/context-consumer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAC,MAAM,WAAW,CAAC;AAIvE;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B;;;;;;;;;;;;;OAaG;IACH,QAAQ,EAAE,SAAS;IAEnB;;;;;;;;OAQG;IACH,WAAW,EAAE,SAAS;IAEtB;;;;;;;;;;;;OAYG;IACH,SAAS,EAAE,SAAS;IAEpB;;;;;;;;;;;;OAYG;IACH,WAAW,EAAE,WAAW;IAExB;;;;;;;;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;;;;;;;;WAQG;QACH,WAAW,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAwC;QAEnF;;;;;;;;;;WAUG;QACH,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CACJ;QAErC;;;;;;;;;;WAUG;QACH,WAAW,EAAE,WAAW;KACf,CAAA;CACH,CAAC","sourcesContent":["import {getDetail, subscribe, unsubscribe, untilNext} from './core.js';\n\nimport type {Stringifyable, OmitFirstParam} from '@alwatr/type';\n\n/**\n * Context consumer interface.\n */\nexport const contextConsumer = {\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 = contextConsumer.getValue<ProductListType>('product-list');\n * if (currentProductList === undefined) {\n * // productList not set before or expired.\n * }\n * ```\n */\n getValue: getDetail,\n\n /**\n * Waits until the context value changes.\n *\n * Example:\n *\n * ```ts\n * const newProductList = await contextConsumer.untilChange<ProductListType>('product-list');\n * ```\n */\n untilChange: untilNext,\n\n /**\n * Subscribe to context changes, work like addEventListener.\n *\n * Example:\n *\n * ```ts\n * const listener = contextConsumer.subscribe<ProductListType>('product-list', (productList) => {\n * console.log(productList);\n * });\n * // ...\n * contextConsumer.unsubscribe(listener);\n * ```\n */\n subscribe: subscribe,\n\n /**\n * Unsubscribe from context changes, work like removeEventListener.\n *\n * Example:\n *\n * ```ts\n * const listener = contextConsumer.subscribe<ProductListType>('product-list', (productList) => {\n * console.log(productList);\n * });\n * // ...\n * contextConsumer.unsubscribe(listener);\n * ```\n */\n unsubscribe: unsubscribe,\n\n /**\n * Bind this interface to special context.\n *\n * Example:\n *\n * ```ts\n * const productListConsumer = contextConsumer.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 = productListConsumer.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 * Waits until the context value changes.\n *\n * Example:\n *\n * ```ts\n * const newProductList = await productListConsumer.untilChange();\n * ```\n */\n untilChange: untilNext.bind(null, contextId) as OmitFirstParam<typeof untilNext<T>>,\n\n /**\n * Subscribe to context changes, work like addEventListener.\n *\n * Example:\n *\n * ```ts\n * const listener = productListConsumer.subscribe((productList) => console.log(productList));\n * // ...\n * productListConsumer.unsubscribe(listener);\n * ```\n */\n subscribe: subscribe.bind(null, contextId) as unknown as\n OmitFirstParam<typeof subscribe<T>>,\n\n /**\n * Unsubscribe from context changes, work like removeEventListener.\n *\n * Example:\n *\n * ```ts\n * const listener = productListConsumer.subscribe((productList) => console.log(productList));\n * // ...\n * productListConsumer.unsubscribe(listener);\n * ```\n */\n unsubscribe: unsubscribe,\n } as const),\n} as const;\n"]}
|