@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 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
- const cc = currentContext;
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
- throw new Error(`Event context type mismatch: expected ${types
30
- .map(t => `"${t}"`)
31
- .join(', ')}, received "${type}"`);
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
- const cc = currentContext;
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
- throw new Error(`Event context type mismatch: expected ${types
28
- .map(t => `"${t}"`)
29
- .join(', ')}, received "${type}"`);
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-core",
3
- "version": "0.4.31",
3
+ "version": "0.4.33",
4
4
  "description": "@wooksjs/event-core",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",