@quazardous/quarkernel 1.0.10 → 1.0.12
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/src/index.js +2 -2
- package/src/lib/QuarKernel.js +21 -6
- package/types/QuarKernel.d.ts +15 -5
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { QuarKernel, QuarKernelEvent } from './lib/QuarKernel.js';
|
|
1
|
+
import { QuarKernel, QuarKernelEvent, QuarKernelLegacyAsyncFunctionWrapper } from './lib/QuarKernel.js';
|
|
2
2
|
|
|
3
|
-
export { QuarKernel, QuarKernelEvent };
|
|
3
|
+
export { QuarKernel, QuarKernelEvent, QuarKernelLegacyAsyncFunctionWrapper };
|
package/src/lib/QuarKernel.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
/* eslint-disable no-plusplus */
|
|
2
2
|
import toposort from 'toposort';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @class LegacyAsync provides a way to handle async eventListenerCallback for old stacks
|
|
6
|
+
*/
|
|
7
|
+
class QuarKernelLegacyAsyncFunctionWrapper {
|
|
8
|
+
/**
|
|
9
|
+
* @param {async eventListenerCallback} asyncCallback
|
|
10
|
+
*/
|
|
11
|
+
constructor(asyncCallback) {
|
|
12
|
+
this.asyncCallback = asyncCallback;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
4
16
|
class GraphNode {
|
|
5
17
|
/**
|
|
6
18
|
* @param {string} target
|
|
@@ -57,20 +69,23 @@ class GraphNodeProcessor {
|
|
|
57
69
|
processAll(e) {
|
|
58
70
|
return Promise.all(
|
|
59
71
|
this.nodes.map(n => this.process(n, e))
|
|
60
|
-
);
|
|
72
|
+
).then(() => e);
|
|
61
73
|
}
|
|
62
74
|
|
|
63
75
|
/**
|
|
64
76
|
* @param {GraphNode} node
|
|
65
77
|
* @param {QuarKernelEvent} e
|
|
66
|
-
* @return {Promise
|
|
78
|
+
* @return {Promise<*>}
|
|
67
79
|
* @private
|
|
68
80
|
*/
|
|
69
81
|
process(node, e) {
|
|
70
82
|
const process = this.processMap[node.name];
|
|
71
83
|
if (!process.promise) {
|
|
72
84
|
let then = null;
|
|
73
|
-
if (node.callback
|
|
85
|
+
if (node.callback instanceof QuarKernelLegacyAsyncFunctionWrapper) {
|
|
86
|
+
// handle legacy async
|
|
87
|
+
then = () => node.callback.asyncCallback(e, node.target);
|
|
88
|
+
} else if (node.callback.constructor.name === 'AsyncFunction') {
|
|
74
89
|
// handle async
|
|
75
90
|
then = () => node.callback(e, node.target);
|
|
76
91
|
} else {
|
|
@@ -81,7 +96,7 @@ class GraphNodeProcessor {
|
|
|
81
96
|
}
|
|
82
97
|
process.promise = this.processDependencies(node, e).then(then);
|
|
83
98
|
}
|
|
84
|
-
return process.promise
|
|
99
|
+
return process.promise;
|
|
85
100
|
}
|
|
86
101
|
|
|
87
102
|
/**
|
|
@@ -242,7 +257,7 @@ class QuarKernel {
|
|
|
242
257
|
* Register for some event.
|
|
243
258
|
*
|
|
244
259
|
* @param {string} type Type of event to listen to
|
|
245
|
-
* @param {eventCallback|eventAsyncCallback} callback
|
|
260
|
+
* @param {eventCallback|eventAsyncCallback|QuarKernelLegacyAsyncFunctionWrapper} callback
|
|
246
261
|
* @param {string} [target] A unique code for the target listener
|
|
247
262
|
* @param {string|Array<string>} [dependencies] A list of targets dependencies
|
|
248
263
|
* In the event scope, callbacks will be fired according to dependencies
|
|
@@ -387,4 +402,4 @@ class QuarKernel {
|
|
|
387
402
|
}
|
|
388
403
|
}
|
|
389
404
|
|
|
390
|
-
export { QuarKernel, QuarKernelEvent };
|
|
405
|
+
export { QuarKernel, QuarKernelEvent, QuarKernelLegacyAsyncFunctionWrapper };
|
package/types/QuarKernel.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export type eventListenerCallback = (e?: QuarKernelEvent) => any;
|
|
2
2
|
export type composeTriggerCallback = (stack?: {
|
|
3
|
-
[x: string]:
|
|
3
|
+
[x: string]: {
|
|
4
4
|
e: QuarKernelEvent;
|
|
5
5
|
p: Promise<QuarKernelEvent>;
|
|
6
|
-
}
|
|
6
|
+
}[];
|
|
7
7
|
}) => any;
|
|
8
8
|
export type composeEventFactory = (stack?: {
|
|
9
|
-
[x: string]:
|
|
9
|
+
[x: string]: QuarKernelEvent[];
|
|
10
10
|
}) => QuarKernelEvent;
|
|
11
11
|
export type eventCallback = (e?: QuarKernelEvent, target?: string) => any;
|
|
12
12
|
export type eventAsyncCallback = () => any;
|
|
@@ -67,12 +67,12 @@ export class QuarKernel {
|
|
|
67
67
|
* Register for some event.
|
|
68
68
|
*
|
|
69
69
|
* @param {string} type Type of event to listen to
|
|
70
|
-
* @param {eventCallback|eventAsyncCallback} callback
|
|
70
|
+
* @param {eventCallback|eventAsyncCallback|QuarKernelLegacyAsyncFunctionWrapper} callback
|
|
71
71
|
* @param {string} [target] A unique code for the target listener
|
|
72
72
|
* @param {string|Array<string>} [dependencies] A list of targets dependencies
|
|
73
73
|
* In the event scope, callbacks will be fired according to dependencies
|
|
74
74
|
*/
|
|
75
|
-
addEventListener(type: string, callback: eventCallback | eventAsyncCallback, target?: string, dependencies?: string | Array<string>): void;
|
|
75
|
+
addEventListener(type: string, callback: eventCallback | eventAsyncCallback | QuarKernelLegacyAsyncFunctionWrapper, target?: string, dependencies?: string | Array<string>): void;
|
|
76
76
|
/**
|
|
77
77
|
* Create a composite trigger.
|
|
78
78
|
*
|
|
@@ -120,3 +120,13 @@ export class QuarKernelEvent {
|
|
|
120
120
|
param: any;
|
|
121
121
|
context: any;
|
|
122
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* @class LegacyAsync provides a way to handle async eventListenerCallback for old stacks
|
|
125
|
+
*/
|
|
126
|
+
export class QuarKernelLegacyAsyncFunctionWrapper {
|
|
127
|
+
/**
|
|
128
|
+
* @param {async eventListenerCallback} asyncCallback
|
|
129
|
+
*/
|
|
130
|
+
constructor(asyncCallback: any);
|
|
131
|
+
asyncCallback: any;
|
|
132
|
+
}
|