@wooksjs/event-core 0.4.31 → 0.4.33
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/dist/index.cjs +9 -4
- package/dist/index.mjs +9 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -21,14 +21,19 @@ function useEventContext(expectedTypes) {
|
|
|
21
21
|
if (!currentContext) {
|
|
22
22
|
throw new Error('Event context does not exist. Use event context synchronously within the runtime of the event.');
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
let cc = currentContext;
|
|
25
25
|
if (expectedTypes || typeof expectedTypes === 'string') {
|
|
26
26
|
const type = cc.event.type;
|
|
27
27
|
const types = typeof expectedTypes === 'string' ? [expectedTypes] : expectedTypes;
|
|
28
28
|
if (!types.includes(type)) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
if (cc.parentCtx?.event.type && types.includes(cc.parentCtx.event.type)) {
|
|
30
|
+
cc = cc.parentCtx;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
throw new Error(`Event context type mismatch: expected ${types
|
|
34
|
+
.map(t => `"${t}"`)
|
|
35
|
+
.join(', ')}, received "${type}"`);
|
|
36
|
+
}
|
|
32
37
|
}
|
|
33
38
|
}
|
|
34
39
|
return _getCtxHelpers(cc);
|
package/dist/index.mjs
CHANGED
|
@@ -19,14 +19,19 @@ function useEventContext(expectedTypes) {
|
|
|
19
19
|
if (!currentContext) {
|
|
20
20
|
throw new Error('Event context does not exist. Use event context synchronously within the runtime of the event.');
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
let cc = currentContext;
|
|
23
23
|
if (expectedTypes || typeof expectedTypes === 'string') {
|
|
24
24
|
const type = cc.event.type;
|
|
25
25
|
const types = typeof expectedTypes === 'string' ? [expectedTypes] : expectedTypes;
|
|
26
26
|
if (!types.includes(type)) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
if (cc.parentCtx?.event.type && types.includes(cc.parentCtx.event.type)) {
|
|
28
|
+
cc = cc.parentCtx;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
throw new Error(`Event context type mismatch: expected ${types
|
|
32
|
+
.map(t => `"${t}"`)
|
|
33
|
+
.join(', ')}, received "${type}"`);
|
|
34
|
+
}
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
return _getCtxHelpers(cc);
|