shelving 1.49.0 → 1.49.1
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/package.json +1 -1
- package/util/function.d.ts +4 -2
- package/util/function.js +7 -2
package/package.json
CHANGED
package/util/function.d.ts
CHANGED
|
@@ -10,9 +10,11 @@ export declare const PASSTHROUGH: <T>(value: T) => T;
|
|
|
10
10
|
export declare const BLACKHOLE: (...args: Arguments) => void | undefined;
|
|
11
11
|
/** Function that receives a dispatched value. */
|
|
12
12
|
export declare type Dispatcher<T extends Arguments = []> = (...value: T) => void;
|
|
13
|
+
/** Function that receives a dispatched value. */
|
|
14
|
+
export declare type AsyncDispatcher<T extends Arguments = []> = (...value: T) => void | PromiseLike<void>;
|
|
13
15
|
/** Safely dispatch a value to a dispatcher function. */
|
|
14
|
-
export declare function dispatch<T extends Arguments>(dispatcher: Dispatcher<T>, ...value: T): void;
|
|
16
|
+
export declare function dispatch<T extends Arguments>(dispatcher: Dispatcher<T> | AsyncDispatcher<T>, ...value: T): void;
|
|
15
17
|
/** Safely dispatch a value to a dispatcher method on an object. */
|
|
16
18
|
export declare function dispatchMethod<T extends Arguments, M extends string | symbol>(obj: {
|
|
17
|
-
[K in M]: Dispatcher<T>;
|
|
19
|
+
[K in M]: Dispatcher<T> | AsyncDispatcher<T>;
|
|
18
20
|
}, key: M, ...value: T): void;
|
package/util/function.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isAsync } from "./async.js";
|
|
1
2
|
import { logError } from "./error.js";
|
|
2
3
|
/** Is a value a function? */
|
|
3
4
|
export const isFunction = (v) => typeof v === "function";
|
|
@@ -8,7 +9,9 @@ export const BLACKHOLE = () => undefined;
|
|
|
8
9
|
/** Safely dispatch a value to a dispatcher function. */
|
|
9
10
|
export function dispatch(dispatcher, ...value) {
|
|
10
11
|
try {
|
|
11
|
-
dispatcher(...value);
|
|
12
|
+
const result = dispatcher(...value);
|
|
13
|
+
if (isAsync(result))
|
|
14
|
+
result.then(BLACKHOLE, logError);
|
|
12
15
|
}
|
|
13
16
|
catch (thrown) {
|
|
14
17
|
logError(thrown);
|
|
@@ -17,7 +20,9 @@ export function dispatch(dispatcher, ...value) {
|
|
|
17
20
|
/** Safely dispatch a value to a dispatcher method on an object. */
|
|
18
21
|
export function dispatchMethod(obj, key, ...value) {
|
|
19
22
|
try {
|
|
20
|
-
obj[key](...value);
|
|
23
|
+
const result = obj[key](...value);
|
|
24
|
+
if (isAsync(result))
|
|
25
|
+
result.then(BLACKHOLE, logError);
|
|
21
26
|
}
|
|
22
27
|
catch (thrown) {
|
|
23
28
|
logError(thrown);
|