@wooksjs/event-core 0.6.4 → 0.6.6

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
@@ -86,6 +86,8 @@ if (_g[STORAGE_KEY]) {
86
86
  const asyncStorage = _g[STORAGE_KEY];
87
87
  /** Symbol key for caching store accessors directly on the context object */
88
88
  const _storeCacheKey = Symbol("storeCache");
89
+ /** Symbol key for caching the full helpers object on the context */
90
+ const _helpersCacheKey = Symbol("helpersCache");
89
91
  /**
90
92
  * Creates a new async event context and returns a runner function to execute callbacks within it.
91
93
  *
@@ -117,9 +119,10 @@ function useAsyncEventContext(expectedTypes) {
117
119
  return _getCtxHelpers(cc);
118
120
  }
119
121
  function _getCtxHelpers(cc) {
120
- const ccAny = cc;
121
- if (!ccAny[_storeCacheKey]) ccAny[_storeCacheKey] = /* @__PURE__ */ new Map();
122
- const _storeCache = ccAny[_storeCacheKey];
122
+ const ccRec = cc;
123
+ if (ccRec[_helpersCacheKey]) return ccRec[_helpersCacheKey];
124
+ if (!ccRec[_storeCacheKey]) ccRec[_storeCacheKey] = /* @__PURE__ */ new Map();
125
+ const _storeCache = ccRec[_storeCacheKey];
123
126
  /**
124
127
  * Hook to an event store property
125
128
  *
@@ -133,6 +136,7 @@ function _getCtxHelpers(cc) {
133
136
  const setSection = (v) => {
134
137
  cc[key] = v;
135
138
  };
139
+ const _hookCache = /* @__PURE__ */ new Map();
136
140
  const obj = {
137
141
  value: null,
138
142
  hook,
@@ -155,6 +159,9 @@ function _getCtxHelpers(cc) {
155
159
  return setNested(key2, getter());
156
160
  }
157
161
  function hook(key2) {
162
+ const hookKey = key2;
163
+ const cached = _hookCache.get(hookKey);
164
+ if (cached) return cached;
158
165
  const hookObj = {
159
166
  value: null,
160
167
  isDefined: null
@@ -164,6 +171,7 @@ function _getCtxHelpers(cc) {
164
171
  get: () => getNested(key2)
165
172
  });
166
173
  attachHook(hookObj, { get: () => hasNested(key2) }, "isDefined");
174
+ _hookCache.set(hookKey, hookObj);
167
175
  return hookObj;
168
176
  }
169
177
  function setNested(key2, v) {
@@ -225,6 +233,7 @@ function _getCtxHelpers(cc) {
225
233
  return _getCtxHelpers(cc.parentCtx);
226
234
  }
227
235
  };
236
+ ccRec[_helpersCacheKey] = helpers;
228
237
  return helpers;
229
238
  }
230
239
 
package/dist/index.d.ts CHANGED
@@ -85,7 +85,7 @@ declare const asyncStorage: AsyncLocalStorage<TGenericContextStore>;
85
85
  * @param data - Initial context store data including the event object and options.
86
86
  * @returns A function that runs a callback within the created async context.
87
87
  */
88
- declare function createAsyncEventContext<S = TEmpty, EventTypeToCreate = TEmpty>(data: S & TGenericContextStore<EventTypeToCreate>): <T>(cb: (...a: any[]) => T) => T;
88
+ declare function createAsyncEventContext<S = TEmpty, EventTypeToCreate = TEmpty>(data: S & TGenericContextStore<EventTypeToCreate>): <T>(cb: (...a: unknown[]) => T) => T;
89
89
  /**
90
90
  * Retrieves the current async event context and returns helpers for reading/writing the store.
91
91
  *
package/dist/index.mjs CHANGED
@@ -63,6 +63,8 @@ if (_g[STORAGE_KEY]) {
63
63
  const asyncStorage = _g[STORAGE_KEY];
64
64
  /** Symbol key for caching store accessors directly on the context object */
65
65
  const _storeCacheKey = Symbol("storeCache");
66
+ /** Symbol key for caching the full helpers object on the context */
67
+ const _helpersCacheKey = Symbol("helpersCache");
66
68
  /**
67
69
  * Creates a new async event context and returns a runner function to execute callbacks within it.
68
70
  *
@@ -94,9 +96,10 @@ function useAsyncEventContext(expectedTypes) {
94
96
  return _getCtxHelpers(cc);
95
97
  }
96
98
  function _getCtxHelpers(cc) {
97
- const ccAny = cc;
98
- if (!ccAny[_storeCacheKey]) ccAny[_storeCacheKey] = /* @__PURE__ */ new Map();
99
- const _storeCache = ccAny[_storeCacheKey];
99
+ const ccRec = cc;
100
+ if (ccRec[_helpersCacheKey]) return ccRec[_helpersCacheKey];
101
+ if (!ccRec[_storeCacheKey]) ccRec[_storeCacheKey] = /* @__PURE__ */ new Map();
102
+ const _storeCache = ccRec[_storeCacheKey];
100
103
  /**
101
104
  * Hook to an event store property
102
105
  *
@@ -110,6 +113,7 @@ function _getCtxHelpers(cc) {
110
113
  const setSection = (v) => {
111
114
  cc[key] = v;
112
115
  };
116
+ const _hookCache = /* @__PURE__ */ new Map();
113
117
  const obj = {
114
118
  value: null,
115
119
  hook,
@@ -132,6 +136,9 @@ function _getCtxHelpers(cc) {
132
136
  return setNested(key2, getter());
133
137
  }
134
138
  function hook(key2) {
139
+ const hookKey = key2;
140
+ const cached = _hookCache.get(hookKey);
141
+ if (cached) return cached;
135
142
  const hookObj = {
136
143
  value: null,
137
144
  isDefined: null
@@ -141,6 +148,7 @@ function _getCtxHelpers(cc) {
141
148
  get: () => getNested(key2)
142
149
  });
143
150
  attachHook(hookObj, { get: () => hasNested(key2) }, "isDefined");
151
+ _hookCache.set(hookKey, hookObj);
144
152
  return hookObj;
145
153
  }
146
154
  function setNested(key2, v) {
@@ -202,6 +210,7 @@ function _getCtxHelpers(cc) {
202
210
  return _getCtxHelpers(cc.parentCtx);
203
211
  }
204
212
  };
213
+ ccRec[_helpersCacheKey] = helpers;
205
214
  return helpers;
206
215
  }
207
216
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-core",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "description": "@wooksjs/event-core",
5
5
  "keywords": [
6
6
  "api",