mutts 1.0.8 → 1.0.10

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.
Files changed (195) hide show
  1. package/README.md +77 -35
  2. package/dist/browser.cjs +2144 -5355
  3. package/dist/browser.cjs.map +1 -1
  4. package/dist/browser.d.ts +2 -1655
  5. package/dist/browser.dev.cjs +110 -0
  6. package/dist/browser.dev.cjs.map +1 -0
  7. package/dist/browser.dev.d.ts +2 -0
  8. package/dist/browser.dev.esm.js +5 -0
  9. package/dist/browser.dev.esm.js.map +1 -0
  10. package/dist/browser.esm.js +20 -107
  11. package/dist/browser.esm.js.map +1 -1
  12. package/dist/chunks/{async-browser-CA0jPWIi.cjs → async-browser-BU_IfxYD.cjs} +19 -107
  13. package/dist/chunks/async-browser-BU_IfxYD.cjs.map +1 -0
  14. package/dist/chunks/{async-core-UqHzvJ-S.cjs → async-core-CRLKP3l-.cjs} +8 -4
  15. package/dist/chunks/async-core-CRLKP3l-.cjs.map +1 -0
  16. package/dist/chunks/{async-node-BYHuGTni.cjs → async-node-3PrbVAbB.cjs} +7 -12
  17. package/dist/chunks/async-node-3PrbVAbB.cjs.map +1 -0
  18. package/dist/chunks/index-CaaQQlPJ.esm.js +3174 -0
  19. package/dist/chunks/index-CaaQQlPJ.esm.js.map +1 -0
  20. package/dist/chunks/node-nKJBk8iJ.esm.js +96 -0
  21. package/dist/chunks/node-nKJBk8iJ.esm.js.map +1 -0
  22. package/dist/chunks/proxy-Dtg-bJ3T.cjs +3763 -0
  23. package/dist/chunks/proxy-Dtg-bJ3T.cjs.map +1 -0
  24. package/dist/chunks/proxy-r7lARftl.esm.js +3701 -0
  25. package/dist/chunks/proxy-r7lARftl.esm.js.map +1 -0
  26. package/dist/debug.cjs +980 -0
  27. package/dist/debug.cjs.map +1 -0
  28. package/dist/debug.d.ts +208 -0
  29. package/dist/debug.esm.js +950 -0
  30. package/dist/debug.esm.js.map +1 -0
  31. package/dist/devtools/manifest.json +1 -1
  32. package/dist/devtools/panel.html +1 -1
  33. package/dist/devtools/panel.js +107 -94
  34. package/dist/devtools/panel.js.map +1 -1
  35. package/dist/index.d.ts +1447 -13
  36. package/dist/mutts.umd.js +7167 -1
  37. package/dist/mutts.umd.js.map +1 -1
  38. package/dist/mutts.umd.min.js +1 -1
  39. package/dist/mutts.umd.min.js.map +1 -1
  40. package/dist/node.cjs +70 -66
  41. package/dist/node.cjs.map +1 -1
  42. package/dist/node.d.ts +2 -1
  43. package/dist/node.dev.cjs +110 -0
  44. package/dist/node.dev.cjs.map +1 -0
  45. package/dist/node.dev.d.ts +2 -0
  46. package/dist/node.dev.esm.js +6 -0
  47. package/dist/node.dev.esm.js.map +1 -0
  48. package/dist/node.esm.js +4 -103
  49. package/dist/node.esm.js.map +1 -1
  50. package/dist/{reactive/types.d.ts → types-W5vD6m2n.d.ts} +186 -93
  51. package/docs/ai/api-reference.md +12 -19
  52. package/docs/ai/manual.md +521 -17
  53. package/docs/events.md +57 -2
  54. package/docs/flavored.md +210 -0
  55. package/docs/reactive/advanced.md +314 -5
  56. package/docs/reactive/attend.md +142 -0
  57. package/docs/reactive/collections.md +76 -39
  58. package/docs/reactive/core.md +100 -14
  59. package/docs/reactive/debugging.md +123 -18
  60. package/docs/reactive/error-handling.md +121 -0
  61. package/docs/reactive/resource.md +125 -0
  62. package/docs/reactive/scan.md +247 -1
  63. package/docs/reactive.md +4 -1
  64. package/docs/std-decorators.md +102 -51
  65. package/docs/utils.md +70 -0
  66. package/docs/zone.md +3 -7
  67. package/package.json +64 -30
  68. package/dist/async/browser.d.ts +0 -2
  69. package/dist/async/browser.d.ts.map +0 -1
  70. package/dist/async/index.d.ts +0 -18
  71. package/dist/async/index.d.ts.map +0 -1
  72. package/dist/async/node.d.ts +0 -2
  73. package/dist/async/node.d.ts.map +0 -1
  74. package/dist/chunks/async-browser-CA0jPWIi.cjs.map +0 -1
  75. package/dist/chunks/async-core-UqHzvJ-S.cjs.map +0 -1
  76. package/dist/chunks/async-node-BYHuGTni.cjs.map +0 -1
  77. package/dist/chunks/index-DhaOVusv.esm.js +0 -6411
  78. package/dist/chunks/index-DhaOVusv.esm.js.map +0 -1
  79. package/dist/decorator.d.ts +0 -106
  80. package/dist/decorator.d.ts.map +0 -1
  81. package/dist/destroyable.d.ts +0 -87
  82. package/dist/destroyable.d.ts.map +0 -1
  83. package/dist/entry-browser.d.ts +0 -3
  84. package/dist/entry-browser.d.ts.map +0 -1
  85. package/dist/entry-node.d.ts +0 -3
  86. package/dist/entry-node.d.ts.map +0 -1
  87. package/dist/eventful.d.ts +0 -18
  88. package/dist/eventful.d.ts.map +0 -1
  89. package/dist/index.d.ts.map +0 -1
  90. package/dist/indexable.d.ts +0 -243
  91. package/dist/indexable.d.ts.map +0 -1
  92. package/dist/introspection.d.ts +0 -27
  93. package/dist/introspection.d.ts.map +0 -1
  94. package/dist/iterableWeak.d.ts +0 -53
  95. package/dist/iterableWeak.d.ts.map +0 -1
  96. package/dist/mixins.d.ts +0 -25
  97. package/dist/mixins.d.ts.map +0 -1
  98. package/dist/promiseChain.d.ts +0 -20
  99. package/dist/promiseChain.d.ts.map +0 -1
  100. package/dist/reactive/array.d.ts +0 -49
  101. package/dist/reactive/array.d.ts.map +0 -1
  102. package/dist/reactive/buffer.d.ts +0 -44
  103. package/dist/reactive/buffer.d.ts.map +0 -1
  104. package/dist/reactive/change.d.ts +0 -29
  105. package/dist/reactive/change.d.ts.map +0 -1
  106. package/dist/reactive/debug.d.ts +0 -111
  107. package/dist/reactive/debug.d.ts.map +0 -1
  108. package/dist/reactive/deep-touch.d.ts +0 -28
  109. package/dist/reactive/deep-touch.d.ts.map +0 -1
  110. package/dist/reactive/deep-watch-state.d.ts +0 -25
  111. package/dist/reactive/deep-watch-state.d.ts.map +0 -1
  112. package/dist/reactive/deep-watch.d.ts +0 -19
  113. package/dist/reactive/deep-watch.d.ts.map +0 -1
  114. package/dist/reactive/effect-context.d.ts +0 -7
  115. package/dist/reactive/effect-context.d.ts.map +0 -1
  116. package/dist/reactive/effects.d.ts +0 -151
  117. package/dist/reactive/effects.d.ts.map +0 -1
  118. package/dist/reactive/index.d.ts +0 -20
  119. package/dist/reactive/index.d.ts.map +0 -1
  120. package/dist/reactive/interface.d.ts +0 -64
  121. package/dist/reactive/interface.d.ts.map +0 -1
  122. package/dist/reactive/map.d.ts +0 -30
  123. package/dist/reactive/map.d.ts.map +0 -1
  124. package/dist/reactive/memoize.d.ts +0 -5
  125. package/dist/reactive/memoize.d.ts.map +0 -1
  126. package/dist/reactive/non-reactive-state.d.ts +0 -9
  127. package/dist/reactive/non-reactive-state.d.ts.map +0 -1
  128. package/dist/reactive/non-reactive.d.ts +0 -11
  129. package/dist/reactive/non-reactive.d.ts.map +0 -1
  130. package/dist/reactive/project.d.ts +0 -41
  131. package/dist/reactive/project.d.ts.map +0 -1
  132. package/dist/reactive/proxy-state.d.ts +0 -8
  133. package/dist/reactive/proxy-state.d.ts.map +0 -1
  134. package/dist/reactive/proxy.d.ts +0 -23
  135. package/dist/reactive/proxy.d.ts.map +0 -1
  136. package/dist/reactive/record.d.ts +0 -116
  137. package/dist/reactive/record.d.ts.map +0 -1
  138. package/dist/reactive/register.d.ts +0 -64
  139. package/dist/reactive/register.d.ts.map +0 -1
  140. package/dist/reactive/registry.d.ts +0 -20
  141. package/dist/reactive/registry.d.ts.map +0 -1
  142. package/dist/reactive/set.d.ts +0 -28
  143. package/dist/reactive/set.d.ts.map +0 -1
  144. package/dist/reactive/tracking.d.ts +0 -7
  145. package/dist/reactive/tracking.d.ts.map +0 -1
  146. package/dist/reactive/types.d.ts.map +0 -1
  147. package/dist/std-decorators.d.ts +0 -50
  148. package/dist/std-decorators.d.ts.map +0 -1
  149. package/dist/utils.d.ts +0 -49
  150. package/dist/utils.d.ts.map +0 -1
  151. package/dist/zone.d.ts +0 -40
  152. package/dist/zone.d.ts.map +0 -1
  153. package/docs/reactive/project.md +0 -93
  154. package/src/async/browser.ts +0 -319
  155. package/src/async/index.ts +0 -23
  156. package/src/async/node.ts +0 -104
  157. package/src/decorator.ts +0 -272
  158. package/src/destroyable.ts +0 -199
  159. package/src/entry-browser.ts +0 -5
  160. package/src/entry-node.ts +0 -5
  161. package/src/eventful.ts +0 -77
  162. package/src/index.d.ts +0 -12
  163. package/src/index.ts +0 -64
  164. package/src/indexable.ts +0 -526
  165. package/src/introspection.ts +0 -59
  166. package/src/iterableWeak.ts +0 -233
  167. package/src/mixins.ts +0 -123
  168. package/src/promiseChain.ts +0 -110
  169. package/src/reactive/array.ts +0 -507
  170. package/src/reactive/buffer.ts +0 -168
  171. package/src/reactive/change.ts +0 -138
  172. package/src/reactive/debug.ts +0 -517
  173. package/src/reactive/deep-touch.ts +0 -268
  174. package/src/reactive/deep-watch-state.ts +0 -82
  175. package/src/reactive/deep-watch.ts +0 -168
  176. package/src/reactive/effect-context.ts +0 -18
  177. package/src/reactive/effects.ts +0 -1382
  178. package/src/reactive/index.ts +0 -75
  179. package/src/reactive/interface.ts +0 -210
  180. package/src/reactive/map.ts +0 -158
  181. package/src/reactive/memoize.ts +0 -163
  182. package/src/reactive/non-reactive-state.ts +0 -49
  183. package/src/reactive/non-reactive.ts +0 -43
  184. package/src/reactive/project.ts +0 -453
  185. package/src/reactive/proxy-state.ts +0 -27
  186. package/src/reactive/proxy.ts +0 -264
  187. package/src/reactive/record.ts +0 -196
  188. package/src/reactive/register.ts +0 -419
  189. package/src/reactive/registry.ts +0 -59
  190. package/src/reactive/set.ts +0 -130
  191. package/src/reactive/tracking.ts +0 -44
  192. package/src/reactive/types.ts +0 -440
  193. package/src/std-decorators.ts +0 -217
  194. package/src/utils.ts +0 -301
  195. package/src/zone.ts +0 -138
package/src/utils.ts DELETED
@@ -1,301 +0,0 @@
1
- type ElementTypes<T extends readonly unknown[]> = {
2
- [K in keyof T]: T[K] extends readonly (infer U)[] ? U : T[K]
3
- }
4
-
5
- /**
6
- * Combines multiple arrays into an array of tuples, stopping at the shortest array length
7
- * @param args - Arrays to zip together
8
- * @returns Array of tuples containing elements from each input array
9
- */
10
- export function zip<T extends (readonly unknown[])[]>(...args: T): ElementTypes<T>[] {
11
- if (!args.length) return []
12
- const minLength = Math.min(...args.map((arr) => arr.length))
13
- const result: ElementTypes<T>[] = []
14
-
15
- for (let i = 0; i < minLength; i++) {
16
- const tuple = args.map((arr) => arr[i]) as ElementTypes<T>
17
- result.push(tuple)
18
- }
19
-
20
- return result
21
- }
22
-
23
- /**
24
- * Checks if two arrays are strictly equal (shallow comparison)
25
- * @param a - First value
26
- * @param b - Second value
27
- * @returns True if arrays are equal or values are strictly equal
28
- */
29
- export function arrayEquals(a: any, b: any): boolean {
30
- if (a === b) return true
31
- if (!Array.isArray(a) || !Array.isArray(b)) return false
32
- if (a.length !== b.length) return false
33
- for (let i = 0; i < a.length; i++) {
34
- if (a[i] !== b[i]) return false
35
- }
36
- return true
37
- }
38
-
39
- const nativeConstructors = new Set<Function>([
40
- Object,
41
- Array,
42
- Date,
43
- Function,
44
- Set,
45
- Map,
46
- WeakMap,
47
- WeakSet,
48
- Promise,
49
- Error,
50
- TypeError,
51
- ReferenceError,
52
- SyntaxError,
53
- RangeError,
54
- URIError,
55
- EvalError,
56
- Reflect,
57
- Proxy,
58
- RegExp,
59
- String,
60
- Number,
61
- Boolean,
62
- ] as Function[])
63
- /**
64
- * Checks if a function is a constructor (class or constructor function)
65
- * @param fn - The function to check
66
- * @returns True if the function is a constructor
67
- */
68
- export function isConstructor(fn: Function): boolean {
69
- return (
70
- fn &&
71
- typeof fn === 'function' &&
72
- (nativeConstructors.has(fn) || fn.toString?.().startsWith('class '))
73
- )
74
- }
75
-
76
- /**
77
- * Renames a function with a new name
78
- * @param fct - The function to rename
79
- * @param name - The new name for the function
80
- * @returns The function with the new name
81
- */
82
- export function renamed<F extends Function>(fct: F, name: string): F {
83
- return Object.defineProperties(fct, {
84
- name: {
85
- value: name,
86
- },
87
- })
88
- }
89
- export const FoolProof = {
90
- get(obj: any, prop: any, receiver: any) {
91
- // Check if Node is available and obj is an instance of Node
92
- if (typeof Node !== 'undefined' && obj instanceof Node) return (obj as any)[prop]
93
- return Reflect.get(obj, prop, receiver)
94
- },
95
- set(obj: any, prop: any, value: any, receiver: any) {
96
- // Check if Node is available and obj is an instance of Node
97
- if (typeof Node !== 'undefined' && obj instanceof Node) {
98
- ;(obj as any)[prop] = value
99
- return true
100
- }
101
- if (!(obj instanceof Object) && !Reflect.has(obj, prop)) {
102
- Object.defineProperty(obj, prop, {
103
- value,
104
- configurable: true,
105
- writable: true,
106
- enumerable: true,
107
- })
108
- return true
109
- }
110
- return Reflect.set(obj, prop, value, receiver)
111
- },
112
- }
113
-
114
- export function isOwnAccessor(obj: any, prop: any) {
115
- const opd = Object.getOwnPropertyDescriptor(obj, prop)
116
- return !!(opd?.get || opd?.set)
117
- }
118
-
119
- /**
120
- * Deeply compares two values.
121
- * For objects, compares prototypes with === and then own properties recursively.
122
- * Uses a cache to handle circular references.
123
- * @param a - First value
124
- * @param b - Second value
125
- * @param cache - Map for circular reference protection (internal use)
126
- * @returns True if values are deeply equal
127
- */
128
- export function deepCompare(a: any, b: any, cache = new Map<object, Set<object>>()): boolean {
129
- if (a === b) return true
130
-
131
- if (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) {
132
- return a === b
133
- }
134
-
135
- // Prototype check
136
- const protoA = Object.getPrototypeOf(a)
137
- const protoB = Object.getPrototypeOf(b)
138
- if (protoA !== protoB) {
139
- console.warn(`[deepCompare] prototype mismatch:`, {
140
- nameA: a?.constructor?.name,
141
- nameB: b?.constructor?.name,
142
- })
143
- return false
144
- }
145
- // Circular reference protection
146
- let compared = cache.get(a)
147
- if (compared?.has(b)) return true
148
- if (!compared) {
149
- compared = new Set()
150
- cache.set(a, compared)
151
- }
152
- compared.add(b)
153
-
154
- // Handle specific object types
155
- if (Array.isArray(a)) {
156
- if (!Array.isArray(b)) {
157
- console.warn(`[deepCompare] B is not an array`)
158
- return false
159
- }
160
- if (a.length !== b.length) {
161
- console.warn(`[deepCompare] array length mismatch:`, { lenA: a.length, lenB: b.length })
162
- return false
163
- }
164
- for (let i = 0; i < a.length; i++) {
165
- if (!deepCompare(a[i], b[i], cache)) {
166
- console.warn(`[deepCompare] array element mismatch at index ${i}`)
167
- return false
168
- }
169
- }
170
- return true
171
- }
172
-
173
- if (a instanceof Date) {
174
- const match = b instanceof Date && a.getTime() === b.getTime()
175
- if (!match) console.warn(`[deepCompare] Date mismatch`)
176
- return match
177
- }
178
- if (a instanceof RegExp) {
179
- const match = b instanceof RegExp && a.toString() === b.toString()
180
- if (!match) console.warn(`[deepCompare] RegExp mismatch`)
181
- return match
182
- }
183
- if (a instanceof Set) {
184
- if (!(b instanceof Set) || a.size !== b.size) {
185
- console.warn(`[deepCompare] Set size mismatch`)
186
- return false
187
- }
188
- for (const val of a) {
189
- let found = false
190
- for (const bVal of b) {
191
- if (deepCompare(val, bVal, cache)) {
192
- found = true
193
- break
194
- }
195
- }
196
- if (!found) {
197
- console.warn(`[deepCompare] missing Set element`)
198
- return false
199
- }
200
- }
201
- return true
202
- }
203
- if (a instanceof Map) {
204
- if (!(b instanceof Map) || a.size !== b.size) {
205
- console.warn(`[deepCompare] Map size mismatch`)
206
- return false
207
- }
208
- for (const [key, val] of a) {
209
- if (!b.has(key)) {
210
- let foundMatch = false
211
- for (const [bKey, bVal] of b) {
212
- if (deepCompare(key, bKey, cache) && deepCompare(val, bVal, cache)) {
213
- foundMatch = true
214
- break
215
- }
216
- }
217
- if (!foundMatch) {
218
- console.warn(`[deepCompare] missing Map key`)
219
- return false
220
- }
221
- } else {
222
- if (!deepCompare(val, b.get(key), cache)) {
223
- console.warn(`[deepCompare] Map value mismatch for key`)
224
- return false
225
- }
226
- }
227
- }
228
- return true
229
- }
230
-
231
- // Compare own properties
232
- const keysA = Object.keys(a)
233
- const keysB = Object.keys(b)
234
- if (keysA.length !== keysB.length) {
235
- console.warn(`[deepCompare] keys length mismatch:`, {
236
- lenA: keysA.length,
237
- lenB: keysB.length,
238
- keysA,
239
- keysB,
240
- a,
241
- b,
242
- })
243
- return false
244
- }
245
-
246
- for (const key of keysA) {
247
- if (!Object.hasOwn(b, key)) {
248
- console.warn(`[deepCompare] missing key ${String(key)} in B`)
249
- return false
250
- }
251
- if (!deepCompare(a[key], b[key], cache)) {
252
- console.warn(`[deepCompare] value mismatch for key ${String(key)}:`, {
253
- valA: a[key],
254
- valB: b[key],
255
- })
256
- return false
257
- }
258
- }
259
-
260
- return true
261
- }
262
-
263
-
264
- const contentRefs = new WeakMap<object, any>()
265
- export function contentRef(container: object) {
266
- if (!contentRefs.has(container))
267
- contentRefs.set(
268
- container,
269
- Object.seal(
270
- Object.create(null, {
271
- contentOf: { value: container, writable: false, configurable: false },
272
- })
273
- )
274
- )
275
- return contentRefs.get(container)
276
- }
277
-
278
- export function tag<T extends object>(name: string, obj: T): T {
279
- Object.defineProperties(obj, {
280
- [Symbol.toStringTag]: {
281
- value: name,
282
- writable: false,
283
- configurable: false,
284
- },
285
- toString: {
286
- value: () => name,
287
- writable: false,
288
- configurable: false,
289
- },
290
- })
291
- return obj
292
- }
293
-
294
- export function named<T extends Function>(name: string, fn: T): T {
295
- Object.defineProperty(fn, 'name', {
296
- value: fn.name ? `${fn.name}::${name}` : name,
297
- writable: false,
298
- configurable: false,
299
- })
300
- return fn
301
- }
package/src/zone.ts DELETED
@@ -1,138 +0,0 @@
1
- import { asyncHooks } from "./async"
2
- import { named, tag } from "./utils"
3
-
4
- interface InternalZoneUse<T> {
5
- enter(value?: T): unknown
6
- leave(entered: unknown): void
7
- }
8
- function isu<T>(z: AZone<T> | InternalZoneUse<T>): InternalZoneUse<T> {
9
- return z as InternalZoneUse<T>
10
- }
11
- export abstract class AZone<T> {
12
- abstract active?: T
13
- protected enter(value?: T): unknown {
14
- const prev = this.active
15
- this.active = value
16
- return prev
17
- }
18
- protected leave(entered: unknown): void {
19
- this.active = entered as T | undefined
20
- }
21
- with<R>(value: T, fn: () => R): R {
22
- const entered = this.enter(value)
23
- let res: R;
24
- try {
25
- res = fn()
26
- } finally {
27
- this.leave(entered)
28
- }
29
- // [HACK]: Sanitization
30
- // See BROWSER_ASYNC_POLYFILL.md
31
- return asyncHooks.sanitizePromise(res) as R
32
- }
33
- root<R>(fn: () => R): R {
34
- let prev = this.enter()
35
- try {
36
- return fn()
37
- } finally {
38
- this.leave(prev)
39
- }
40
- }
41
- get zoned(): FunctionWrapper {
42
- const active = this.active
43
- return named(`${this}@${active}`, (fn) => this.with(active, fn))
44
- }
45
- }
46
-
47
- export type FunctionWrapper = <R>(fn?: () => R) => R
48
-
49
- export class Zone<T> extends AZone<T> {
50
- active: T | undefined
51
- }
52
- type HistoryValue<T> = {present: T | undefined, history: Set<T>}
53
- export class ZoneHistory<T> extends AZone<HistoryValue<T>> {
54
- private history = new Set<T>()
55
- public readonly present: AZone<T>
56
- public has(value: T): boolean {
57
- return this.history.has(value)
58
- }
59
- public some(predicate: (value: T) => boolean): boolean {
60
- for(const value of this.history) if(predicate(value)) return true
61
- return false
62
- }
63
- constructor(private controlled: AZone<T> = new Zone<T>()) {
64
- super()
65
- const self = this
66
- this.present = Object.create(controlled,
67
- Object.getOwnPropertyDescriptors({
68
- get active() { return controlled.active },
69
- set active(value: T | undefined) {
70
- controlled.active = value
71
- },
72
- enter(value?: T) {
73
- if(value && self.history.has(value)) throw new Error('ZoneHistory: re-entering historical zone')
74
- if(value !== undefined) self.history.add(value)
75
- return { added: value, entered: isu(controlled).enter(value) }
76
- },
77
- leave(entered: { added: T | undefined, entered: unknown }) {
78
- if(entered.added !== undefined) self.history.delete(entered.added)
79
- return isu(controlled).leave(entered.entered)
80
- }
81
- })
82
- )
83
- }
84
- get active() {
85
- return {present: this.controlled.active, history: new Set(this.history)}
86
- }
87
- set active(value: HistoryValue<T> | undefined) {
88
- this.history = this.history && new Set(this.history)
89
- this.controlled.active = value?.present
90
- }
91
- }
92
-
93
- export class ZoneAggregator extends AZone<Map<AZone<unknown>, unknown>> {
94
- #zones = new Set<AZone<unknown>>()
95
- constructor(...zones: AZone<unknown>[]) {
96
- super()
97
- for (const z of zones) this.#zones.add(z)
98
- }
99
- get active(): Map<AZone<unknown>, unknown> | undefined {
100
- const rv = new Map<AZone<unknown>, unknown>()
101
- for (const z of this.#zones)
102
- if (z.active !== undefined) rv.set(z, z.active)
103
- return rv
104
- }
105
- set active(value: Map<AZone<unknown>, unknown> | undefined) {
106
- for (const z of this.#zones) z.active = value?.get(z)
107
- }
108
- enter(value?: Map<AZone<unknown>, unknown> | undefined) {
109
- const entered = new Map<AZone<unknown>, unknown>()
110
- for (const z of this.#zones) {
111
- const v = value?.get(z)
112
- entered.set(z, isu(z).enter(v))
113
- }
114
- return entered
115
- }
116
- leave(entered: Map<AZone<unknown>, unknown>): void {
117
- for (const z of this.#zones) isu(z).leave(entered.get(z))
118
- }
119
- add(z: AZone<unknown>) {
120
- this.#zones.add(z)
121
- }
122
- delete(z: AZone<unknown>) {
123
- this.#zones.delete(z)
124
- }
125
- clear() {
126
- this.#zones.clear()
127
- }
128
- }
129
-
130
- export const asyncZone = tag('async', new ZoneAggregator())
131
- asyncHooks.addHook(() => {
132
- const zone = asyncZone.active
133
- return () => {
134
- const prev = asyncZone.active
135
- asyncZone.active = zone
136
- return () => asyncZone.active = prev
137
- }
138
- })