@quazardous/quarkernel 1.0.11 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quazardous/quarkernel",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "type": "module",
5
5
  "description": "Micro Custom Events Kernel",
6
6
  "repository": {
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 };
@@ -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
@@ -70,7 +82,10 @@ class GraphNodeProcessor {
70
82
  const process = this.processMap[node.name];
71
83
  if (!process.promise) {
72
84
  let then = null;
73
- if (node.callback.constructor.name === 'AsyncFunction') {
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 {
@@ -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 };
@@ -1,12 +1,12 @@
1
1
  export type eventListenerCallback = (e?: QuarKernelEvent) => any;
2
2
  export type composeTriggerCallback = (stack?: {
3
- [x: string]: Array<{
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]: Array<QuarKernelEvent>;
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
+ }