mutts 1.0.7 → 1.0.9

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 (191) hide show
  1. package/README.md +72 -17
  2. package/dist/browser.cjs +3111 -0
  3. package/dist/browser.cjs.map +1 -0
  4. package/dist/browser.d.ts +1391 -1
  5. package/dist/browser.esm.js +264 -35
  6. package/dist/browser.esm.js.map +1 -1
  7. package/dist/chunks/async-browser-lvzLOCgk.cjs +297 -0
  8. package/dist/chunks/async-browser-lvzLOCgk.cjs.map +1 -0
  9. package/dist/chunks/async-core-CRLKP3l-.cjs +29 -0
  10. package/dist/chunks/async-core-CRLKP3l-.cjs.map +1 -0
  11. package/dist/chunks/async-node-C3DeIb0y.cjs +96 -0
  12. package/dist/chunks/async-node-C3DeIb0y.cjs.map +1 -0
  13. package/dist/chunks/index-2vea86wD.esm.js +3011 -0
  14. package/dist/chunks/index-2vea86wD.esm.js.map +1 -0
  15. package/dist/chunks/index-CtA2AWl3.esm.js +4376 -0
  16. package/dist/chunks/index-CtA2AWl3.esm.js.map +1 -0
  17. package/dist/chunks/index-VTO-b2vR.cjs +4461 -0
  18. package/dist/chunks/index-VTO-b2vR.cjs.map +1 -0
  19. package/dist/debug/debug.d.ts +122 -0
  20. package/dist/debug/debug.d.ts.map +1 -0
  21. package/dist/debug/index.d.ts +4 -0
  22. package/dist/debug/index.d.ts.map +1 -0
  23. package/dist/debug/lineage-panel.d.ts +5 -0
  24. package/dist/debug/lineage-panel.d.ts.map +1 -0
  25. package/dist/debug/lineage.d.ts +79 -0
  26. package/dist/debug/lineage.d.ts.map +1 -0
  27. package/dist/debug.cjs +35 -0
  28. package/dist/debug.cjs.map +1 -0
  29. package/dist/debug.d.ts +209 -0
  30. package/dist/debug.esm.js +2 -0
  31. package/dist/debug.esm.js.map +1 -0
  32. package/dist/devtools/devtool/devtools.d.ts +1 -0
  33. package/dist/devtools/devtool/devtools.d.ts.map +1 -0
  34. package/dist/devtools/devtool/panel.d.ts +2 -0
  35. package/dist/devtools/devtool/panel.d.ts.map +1 -0
  36. package/dist/index.d.ts +1 -0
  37. package/dist/mutts.umd.js +1 -1
  38. package/dist/mutts.umd.js.map +1 -1
  39. package/dist/mutts.umd.min.js +1 -1
  40. package/dist/mutts.umd.min.js.map +1 -1
  41. package/dist/node.cjs +107 -0
  42. package/dist/node.cjs.map +1 -0
  43. package/dist/node.d.ts +2 -2
  44. package/dist/node.esm.js +86 -33
  45. package/dist/node.esm.js.map +1 -1
  46. package/dist/src/async/browser.d.ts +2 -0
  47. package/dist/src/async/browser.d.ts.map +1 -0
  48. package/dist/src/async/index.d.ts +19 -0
  49. package/dist/src/async/index.d.ts.map +1 -0
  50. package/dist/src/async/node.d.ts +2 -0
  51. package/dist/src/async/node.d.ts.map +1 -0
  52. package/dist/src/decorator.d.ts +106 -0
  53. package/dist/src/decorator.d.ts.map +1 -0
  54. package/dist/src/destroyable.d.ts +87 -0
  55. package/dist/src/destroyable.d.ts.map +1 -0
  56. package/dist/src/entry-browser.d.ts +3 -0
  57. package/dist/src/entry-browser.d.ts.map +1 -0
  58. package/dist/src/entry-node.d.ts +3 -0
  59. package/dist/src/entry-node.d.ts.map +1 -0
  60. package/dist/src/eventful.d.ts +20 -0
  61. package/dist/src/eventful.d.ts.map +1 -0
  62. package/dist/src/flavored.d.ts +33 -0
  63. package/dist/src/flavored.d.ts.map +1 -0
  64. package/dist/src/index.d.ts +14 -0
  65. package/dist/src/index.d.ts.map +1 -0
  66. package/dist/src/indexable.d.ts +243 -0
  67. package/dist/src/indexable.d.ts.map +1 -0
  68. package/dist/src/introspection.d.ts +27 -0
  69. package/dist/src/introspection.d.ts.map +1 -0
  70. package/dist/src/iterableWeak.d.ts +53 -0
  71. package/dist/src/iterableWeak.d.ts.map +1 -0
  72. package/dist/src/mixins.d.ts +25 -0
  73. package/dist/src/mixins.d.ts.map +1 -0
  74. package/dist/src/promiseChain.d.ts +20 -0
  75. package/dist/src/promiseChain.d.ts.map +1 -0
  76. package/dist/src/reactive/array.d.ts +48 -0
  77. package/dist/src/reactive/array.d.ts.map +1 -0
  78. package/dist/src/reactive/buffer.d.ts +120 -0
  79. package/dist/src/reactive/buffer.d.ts.map +1 -0
  80. package/dist/src/reactive/change.d.ts +29 -0
  81. package/dist/src/reactive/change.d.ts.map +1 -0
  82. package/dist/src/reactive/deep-touch.d.ts +28 -0
  83. package/dist/src/reactive/deep-touch.d.ts.map +1 -0
  84. package/dist/src/reactive/deep-watch-state.d.ts +25 -0
  85. package/dist/src/reactive/deep-watch-state.d.ts.map +1 -0
  86. package/dist/src/reactive/deep-watch.d.ts +20 -0
  87. package/dist/src/reactive/deep-watch.d.ts.map +1 -0
  88. package/dist/src/reactive/describe.d.ts +12 -0
  89. package/dist/src/reactive/describe.d.ts.map +1 -0
  90. package/dist/src/reactive/effect-context.d.ts +34 -0
  91. package/dist/src/reactive/effect-context.d.ts.map +1 -0
  92. package/dist/src/reactive/effects.d.ts +164 -0
  93. package/dist/src/reactive/effects.d.ts.map +1 -0
  94. package/dist/src/reactive/index.d.ts +19 -0
  95. package/dist/src/reactive/index.d.ts.map +1 -0
  96. package/dist/src/reactive/map.d.ts +28 -0
  97. package/dist/src/reactive/map.d.ts.map +1 -0
  98. package/dist/src/reactive/memoize.d.ts +28 -0
  99. package/dist/src/reactive/memoize.d.ts.map +1 -0
  100. package/dist/src/reactive/non-reactive-state.d.ts +9 -0
  101. package/dist/src/reactive/non-reactive-state.d.ts.map +1 -0
  102. package/dist/src/reactive/non-reactive.d.ts +11 -0
  103. package/dist/src/reactive/non-reactive.d.ts.map +1 -0
  104. package/dist/src/reactive/project.d.ts +40 -0
  105. package/dist/src/reactive/project.d.ts.map +1 -0
  106. package/dist/src/reactive/proxy-state.d.ts +8 -0
  107. package/dist/src/reactive/proxy-state.d.ts.map +1 -0
  108. package/dist/src/reactive/proxy.d.ts +23 -0
  109. package/dist/src/reactive/proxy.d.ts.map +1 -0
  110. package/dist/src/reactive/record.d.ts +115 -0
  111. package/dist/src/reactive/record.d.ts.map +1 -0
  112. package/dist/src/reactive/register.d.ts +125 -0
  113. package/dist/src/reactive/register.d.ts.map +1 -0
  114. package/dist/src/reactive/registry.d.ts +21 -0
  115. package/dist/src/reactive/registry.d.ts.map +1 -0
  116. package/dist/src/reactive/set.d.ts +26 -0
  117. package/dist/src/reactive/set.d.ts.map +1 -0
  118. package/dist/src/reactive/tracking.d.ts +7 -0
  119. package/dist/src/reactive/tracking.d.ts.map +1 -0
  120. package/dist/src/reactive/types.d.ts +424 -0
  121. package/dist/src/reactive/types.d.ts.map +1 -0
  122. package/dist/src/reactive/watch.d.ts +48 -0
  123. package/dist/src/reactive/watch.d.ts.map +1 -0
  124. package/dist/src/std-decorators.d.ts +45 -0
  125. package/dist/src/std-decorators.d.ts.map +1 -0
  126. package/dist/src/utils.d.ts +49 -0
  127. package/dist/src/utils.d.ts.map +1 -0
  128. package/dist/src/zone.d.ts +40 -0
  129. package/dist/src/zone.d.ts.map +1 -0
  130. package/dist/types-DaHFfhlN.d.ts +414 -0
  131. package/docs/ai/api-reference.md +1 -1
  132. package/docs/ai/manual.md +443 -17
  133. package/docs/events.md +57 -2
  134. package/docs/flavored.md +210 -0
  135. package/docs/reactive/advanced.md +2 -3
  136. package/docs/reactive/attend.md +143 -0
  137. package/docs/reactive/collections.md +55 -0
  138. package/docs/reactive/core.md +120 -4
  139. package/docs/reactive/debugging.md +8 -10
  140. package/docs/reactive/describe.md +85 -0
  141. package/docs/reactive/error-handling.md +121 -0
  142. package/docs/reactive/project.md +1 -1
  143. package/docs/reactive/scan.md +215 -0
  144. package/docs/reactive.md +2 -0
  145. package/docs/std-decorators.md +171 -52
  146. package/docs/zone.md +9 -6
  147. package/package.json +44 -27
  148. package/src/async/browser.ts +277 -41
  149. package/src/async/index.ts +23 -4
  150. package/src/async/node.ts +78 -32
  151. package/src/entry-browser.ts +5 -0
  152. package/src/entry-node.ts +5 -0
  153. package/src/eventful.ts +82 -49
  154. package/src/flavored.ts +106 -0
  155. package/src/index.d.ts +12 -9
  156. package/src/index.ts +2 -1
  157. package/src/introspection.ts +1 -1
  158. package/src/reactive/array.ts +160 -80
  159. package/src/reactive/buffer.ts +187 -27
  160. package/src/reactive/change.ts +16 -23
  161. package/src/reactive/deep-touch.ts +19 -14
  162. package/src/reactive/deep-watch-state.ts +3 -3
  163. package/src/reactive/deep-watch.ts +7 -4
  164. package/src/reactive/describe.ts +39 -0
  165. package/src/reactive/effect-context.ts +71 -6
  166. package/src/reactive/effects.ts +445 -393
  167. package/src/reactive/index.ts +12 -14
  168. package/src/reactive/map.ts +8 -24
  169. package/src/reactive/memoize.ts +26 -3
  170. package/src/reactive/project.md +107 -0
  171. package/src/reactive/project.ts +48 -71
  172. package/src/reactive/proxy.ts +21 -3
  173. package/src/reactive/record.ts +30 -45
  174. package/src/reactive/register.ts +138 -19
  175. package/src/reactive/registry.ts +22 -9
  176. package/src/reactive/set.ts +7 -20
  177. package/src/reactive/tracking.ts +9 -12
  178. package/src/reactive/types.ts +104 -24
  179. package/src/reactive/{interface.ts → watch.ts} +29 -59
  180. package/src/std-decorators.ts +56 -17
  181. package/src/utils.ts +3 -4
  182. package/src/zone.ts +43 -28
  183. package/dist/browser.js +0 -161
  184. package/dist/browser.js.map +0 -1
  185. package/dist/chunks/index-BFYK02LG.js +0 -6378
  186. package/dist/chunks/index-BFYK02LG.js.map +0 -1
  187. package/dist/chunks/index-CNR6QRUl.esm.js +0 -6291
  188. package/dist/chunks/index-CNR6QRUl.esm.js.map +0 -1
  189. package/dist/node.js +0 -136
  190. package/dist/node.js.map +0 -1
  191. package/src/reactive/debug.ts +0 -517
@@ -1,22 +1,18 @@
1
1
  import { decorator, type GenericClassDecorator } from '../decorator'
2
2
  import { deepWatch } from './deep-watch'
3
- import { effect, untracked } from './effects'
3
+ import { effect } from './effects'
4
4
  import { isNonReactive, nonReactiveClass, nonReactiveObjects } from './non-reactive-state'
5
5
  import { unwrap } from './proxy-state'
6
6
  import { markWithRoot } from './registry'
7
7
  import { dependant } from './tracking'
8
8
  import {
9
- type DependencyAccess,
9
+ type EffectAccess,
10
+ type EffectCleanup,
10
11
  nonReactiveMark,
11
- type ScopedCallback,
12
+ stopped,
12
13
  unreactiveProperties,
13
14
  } from './types'
14
15
 
15
- /**
16
- * Symbol for accessing the cleanup function on cleaned objects
17
- */
18
- export const cleanup = Symbol('cleanup')
19
-
20
16
  //#region watch
21
17
 
22
18
  const unsetYet = Symbol('unset-yet')
@@ -38,10 +34,10 @@ export interface WatchOptions {
38
34
  * @returns Cleanup function to stop watching
39
35
  */
40
36
  export function watch<T>(
41
- value: (dep: DependencyAccess) => T,
37
+ value: (dep: EffectAccess) => T,
42
38
  changed: (value: T, oldValue?: T) => void,
43
39
  options?: Omit<WatchOptions, 'deep'> & { deep?: false }
44
- ): ScopedCallback
40
+ ): EffectCleanup
45
41
  /**
46
42
  * Watches a reactive value with deep watching enabled
47
43
  * @param value - Function that returns the value to watch
@@ -50,10 +46,10 @@ export function watch<T>(
50
46
  * @returns Cleanup function to stop watching
51
47
  */
52
48
  export function watch<T extends object | any[]>(
53
- value: (dep: DependencyAccess) => T,
49
+ value: (dep: EffectAccess) => T,
54
50
  changed: (value: T, oldValue?: T) => void,
55
51
  options?: Omit<WatchOptions, 'deep'> & { deep: true }
56
- ): ScopedCallback
52
+ ): EffectCleanup
57
53
  /**
58
54
  * Watches a reactive object directly
59
55
  * @param value - The reactive object to watch
@@ -65,7 +61,7 @@ export function watch<T extends object | any[]>(
65
61
  value: T,
66
62
  changed: (value: T) => void,
67
63
  options?: WatchOptions
68
- ): ScopedCallback
64
+ ): EffectCleanup
69
65
 
70
66
  export function watch(
71
67
  value: any, //object | ((dep: DependencyAccess) => object),
@@ -85,7 +81,7 @@ function watchObject(
85
81
  value: object,
86
82
  changed: (value: object) => void,
87
83
  { immediate = false, deep = false } = {}
88
- ): ScopedCallback {
84
+ ): EffectCleanup {
89
85
  if (deep) return deepWatch(value, changed, { immediate })!
90
86
  return effect(function watchObjectEffect() {
91
87
  dependant(value)
@@ -95,12 +91,12 @@ function watchObject(
95
91
  }
96
92
 
97
93
  function watchCallBack<T>(
98
- value: (dep: DependencyAccess) => T,
94
+ value: (dep: EffectAccess) => T,
99
95
  changed: (value: T, oldValue?: T) => void,
100
96
  { immediate = false, deep = false } = {}
101
- ): ScopedCallback {
97
+ ): EffectCleanup {
102
98
  let oldValue: T | typeof unsetYet = unsetYet
103
- let deepCleanup: ScopedCallback | undefined
99
+ let deepCleanup: EffectCleanup | undefined
104
100
  const cbCleanup = effect(
105
101
  markWithRoot(function watchCallBackEffect(access) {
106
102
  const newValue = value(access)
@@ -108,17 +104,22 @@ function watchCallBack<T>(
108
104
  if (oldValue === unsetYet) {
109
105
  if (immediate) changed(newValue)
110
106
  } else changed(newValue, oldValue)
111
- oldValue = newValue
112
- if (deep) {
113
- if (deepCleanup) deepCleanup()
114
- deepCleanup = deepWatch(newValue as object, (value) => changed(value as T, value as T))
115
- }
107
+ oldValue = newValue
108
+ if (deep) {
109
+ if (deepCleanup) deepCleanup()
110
+ deepCleanup = deepWatch(newValue as object, (value) => changed(value as T, value as T))
111
+ }
116
112
  }, value)
117
113
  )
118
- return () => {
119
- cbCleanup()
120
- if (deepCleanup) deepCleanup()
121
- }
114
+ return Object.defineProperties(
115
+ () => {
116
+ cbCleanup()
117
+ if (deepCleanup) deepCleanup()
118
+ },
119
+ {
120
+ [stopped]: { get: () => cbCleanup[stopped] },
121
+ }
122
+ ) as EffectCleanup
122
123
  }
123
124
 
124
125
  //#endregion
@@ -129,7 +130,7 @@ function watchCallBack<T>(
129
130
  * Mark an object as non-reactive. This object and all its properties will never be made reactive.
130
131
  * @param obj - The object to mark as non-reactive
131
132
  */
132
- function deepNonReactive<T>(obj: T): T {
133
+ function shallowNonReactive<T>(obj: T): T {
133
134
  obj = unwrap(obj)
134
135
  if (isNonReactive(obj)) return obj
135
136
  try {
@@ -152,7 +153,7 @@ function unreactiveApplication<T extends object>(
152
153
  ...args: (keyof T)[]
153
154
  ): GenericClassDecorator<T> | T {
154
155
  return typeof arg1 === 'object'
155
- ? deepNonReactive(arg1)
156
+ ? shallowNonReactive(arg1)
156
157
  : (((original) => {
157
158
  // Copy the parent's unreactive properties if they exist
158
159
  original.prototype[unreactiveProperties] = new Set<PropertyKey>(
@@ -177,34 +178,3 @@ export const unreactive = decorator({
177
178
  })
178
179
 
179
180
  //#endregion
180
-
181
- export function cleanedBy<T extends object>(obj: T, cleanupFn: ScopedCallback) {
182
- return Object.defineProperty(obj, cleanup, {
183
- value: cleanupFn,
184
- writable: false,
185
- enumerable: false,
186
- configurable: true,
187
- }) as T & { [cleanup]: ScopedCallback }
188
- }
189
-
190
- //#region greedy caching
191
-
192
- /**
193
- * Creates a derived value that automatically recomputes when dependencies change
194
- * @param compute - Function that computes the derived value
195
- * @returns Object with value and cleanup function
196
- */
197
- export function derived<T>(compute: (dep: DependencyAccess) => T): {
198
- value: T
199
- [cleanup]: ScopedCallback
200
- } {
201
- const rv = { value: undefined as unknown as T }
202
- return cleanedBy(
203
- rv,
204
- untracked(() =>
205
- effect(function derivedEffect(access) {
206
- rv.value = compute(access)
207
- })
208
- )
209
- )
210
- }
@@ -1,4 +1,5 @@
1
1
  import { decorator, type GenericClassDecorator } from './decorator'
2
+ import { flavored } from './flavored'
2
3
 
3
4
  // In order to avoid async re-entrance, we could use zone.js or something like that.
4
5
  const syncCalculating: { object: object; prop: PropertyKey }[] = []
@@ -56,26 +57,64 @@ export function cache(object: Object, propertyKey: PropertyKey, value: any) {
56
57
  * @param descriptor - The descriptor properties to apply
57
58
  * @returns A class decorator that applies the descriptor to specified properties
58
59
  */
59
- export function describe(descriptor: {
60
- enumerable?: boolean
61
- configurable?: boolean // Not modifiable once the property has been defined ?
62
- writable?: boolean
63
- }) {
64
- return <T>(...properties: (keyof T)[]): GenericClassDecorator<T> =>
65
- (Base) => {
66
- return class extends Base {
67
- constructor(...args: any[]) {
68
- super(...args)
69
- for (const key of properties) {
70
- Object.defineProperty(this, key, {
71
- ...Object.getOwnPropertyDescriptor(this, key),
72
- ...descriptor,
73
- })
60
+ export const descriptor = flavored(
61
+ function descriptor(descriptor: {
62
+ enumerable?: boolean
63
+ configurable?: boolean // Not modifiable once the property has been defined
64
+ writable?: boolean
65
+ }) {
66
+ return <T>(...properties: (keyof T)[]): GenericClassDecorator<T> =>
67
+ (Base) => {
68
+ return class extends Base {
69
+ constructor(...args: any[]) {
70
+ super(...args)
71
+ for (const key of properties) {
72
+ const existing = Object.getOwnPropertyDescriptor(this, key)
73
+ Object.defineProperty(this, key, Object.assign(existing || {}, descriptor))
74
+ }
74
75
  }
75
76
  }
76
77
  }
77
- }
78
- }
78
+ },
79
+ {
80
+ /**
81
+ * enumerable: true
82
+ */
83
+ get enumerable() {
84
+ return descriptor({ enumerable: true })
85
+ },
86
+ /**
87
+ * enumerable: false
88
+ */
89
+ get hidden() {
90
+ return descriptor({ enumerable: false })
91
+ },
92
+ /**
93
+ * configurable: true
94
+ */
95
+ get configurable() {
96
+ return descriptor({ configurable: true })
97
+ },
98
+ /**
99
+ * configurable: false
100
+ */
101
+ get frozen() {
102
+ return descriptor({ configurable: false })
103
+ },
104
+ /**
105
+ * writable: true
106
+ */
107
+ get writable() {
108
+ return descriptor({ writable: true })
109
+ },
110
+ /**
111
+ * writable: false
112
+ */
113
+ get readonly() {
114
+ return descriptor({ writable: false })
115
+ },
116
+ }
117
+ )
79
118
 
80
119
  /**
81
120
  * Decorator that marks methods, properties, or classes as deprecated
package/src/utils.ts CHANGED
@@ -260,7 +260,6 @@ export function deepCompare(a: any, b: any, cache = new Map<object, Set<object>>
260
260
  return true
261
261
  }
262
262
 
263
-
264
263
  const contentRefs = new WeakMap<object, any>()
265
264
  export function contentRef(container: object) {
266
265
  if (!contentRefs.has(container))
@@ -275,7 +274,7 @@ export function contentRef(container: object) {
275
274
  return contentRefs.get(container)
276
275
  }
277
276
 
278
- export function tag<T extends object>(obj: T, name: string): T {
277
+ export function tag<T extends object>(name: string, obj: T): T {
279
278
  Object.defineProperties(obj, {
280
279
  [Symbol.toStringTag]: {
281
280
  value: name,
@@ -295,7 +294,7 @@ export function named<T extends Function>(name: string, fn: T): T {
295
294
  Object.defineProperty(fn, 'name', {
296
295
  value: fn.name ? `${fn.name}::${name}` : name,
297
296
  writable: false,
298
- configurable: false,
297
+ configurable: true,
299
298
  })
300
299
  return fn
301
- }
300
+ }
package/src/zone.ts CHANGED
@@ -1,26 +1,37 @@
1
- import { asyncHooks } from "./async"
2
- import { named, tag } from "./utils"
1
+ import { asyncHooks } from './async'
2
+ import { named, tag } from './utils'
3
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
+ }
4
11
  export abstract class AZone<T> {
5
12
  abstract active?: T
6
- enter(value?: T): unknown {
13
+ protected enter(value?: T): unknown {
7
14
  const prev = this.active
8
15
  this.active = value
9
16
  return prev
10
17
  }
11
- leave(entered: unknown): void {
18
+ protected leave(entered: unknown): void {
12
19
  this.active = entered as T | undefined
13
20
  }
14
- with<R>(value: T, fn: () => R): R {
21
+ with<R>(value: T | undefined, fn: () => R): R {
15
22
  const entered = this.enter(value)
23
+ let res: R
16
24
  try {
17
- return fn()
25
+ res = fn()
18
26
  } finally {
19
27
  this.leave(entered)
20
28
  }
29
+ // [HACK]: Sanitization
30
+ // See BROWSER_ASYNC_POLYFILL.md
31
+ return asyncHooks.sanitizePromise(res) as R
21
32
  }
22
33
  root<R>(fn: () => R): R {
23
- let prev = this.enter()
34
+ const prev = this.enter()
24
35
  try {
25
36
  return fn()
26
37
  } finally {
@@ -33,48 +44,53 @@ export abstract class AZone<T> {
33
44
  }
34
45
  }
35
46
 
36
- export type FunctionWrapper = <R>(fn?: () => R) => R
47
+ export type FunctionWrapper = <R>(fn: () => R) => R
37
48
 
38
49
  export class Zone<T> extends AZone<T> {
39
50
  active: T | undefined
40
51
  }
41
- type HistoryValue<T> = {present: T | undefined, history: Set<T>}
52
+
53
+ type HistoryValue<T> = { present: T | undefined; history: Set<T> }
42
54
  export class ZoneHistory<T> extends AZone<HistoryValue<T>> {
43
- private history = new Set<T>()
55
+ private history = new Set<T>()
44
56
  public readonly present: AZone<T>
45
57
  public has(value: T): boolean {
46
58
  return this.history.has(value)
47
59
  }
48
60
  public some(predicate: (value: T) => boolean): boolean {
49
- for(const value of this.history) if(predicate(value)) return true
61
+ for (const value of this.history) if (predicate(value)) return true
50
62
  return false
51
63
  }
52
64
  constructor(private controlled: AZone<T> = new Zone<T>()) {
53
65
  super()
54
66
  const self = this
55
- this.present = Object.create(controlled,
67
+ this.present = Object.create(
68
+ controlled,
56
69
  Object.getOwnPropertyDescriptors({
57
- get active() { return controlled.active },
70
+ get active() {
71
+ return controlled.active
72
+ },
58
73
  set active(value: T | undefined) {
59
74
  controlled.active = value
60
75
  },
61
76
  enter(value?: T) {
62
- if(value && self.history.has(value)) throw new Error('ZoneHistory: re-entering historical zone')
63
- if(value !== undefined) self.history.add(value)
64
- return { added: value, entered: controlled.enter(value) }
77
+ if (value && self.history.has(value))
78
+ throw new Error('ZoneHistory: re-entering historical zone')
79
+ if (value !== undefined) self.history.add(value)
80
+ return { added: value, entered: isu(controlled).enter(value) }
81
+ },
82
+ leave(entered: { added: T | undefined; entered: unknown }) {
83
+ if (entered.added !== undefined) self.history.delete(entered.added)
84
+ return isu(controlled).leave(entered.entered)
65
85
  },
66
- leave(entered: { added: T | undefined, entered: unknown }) {
67
- if(entered.added !== undefined) self.history.delete(entered.added)
68
- return controlled.leave(entered.entered)
69
- }
70
86
  })
71
87
  )
72
88
  }
73
89
  get active() {
74
- return {present: this.controlled.active, history: new Set(this.history)}
90
+ return { present: this.controlled.active, history: new Set(this.history) }
75
91
  }
76
92
  set active(value: HistoryValue<T> | undefined) {
77
- this.history = this.history && new Set(this.history)
93
+ this.history = value?.history ? new Set(value.history) : new Set()
78
94
  this.controlled.active = value?.present
79
95
  }
80
96
  }
@@ -87,8 +103,7 @@ export class ZoneAggregator extends AZone<Map<AZone<unknown>, unknown>> {
87
103
  }
88
104
  get active(): Map<AZone<unknown>, unknown> | undefined {
89
105
  const rv = new Map<AZone<unknown>, unknown>()
90
- for (const z of this.#zones)
91
- if (z.active !== undefined) rv.set(z, z.active)
106
+ for (const z of this.#zones) if (z.active !== undefined) rv.set(z, z.active)
92
107
  return rv
93
108
  }
94
109
  set active(value: Map<AZone<unknown>, unknown> | undefined) {
@@ -98,12 +113,12 @@ export class ZoneAggregator extends AZone<Map<AZone<unknown>, unknown>> {
98
113
  const entered = new Map<AZone<unknown>, unknown>()
99
114
  for (const z of this.#zones) {
100
115
  const v = value?.get(z)
101
- entered.set(z, z.enter(v))
116
+ entered.set(z, isu(z).enter(v))
102
117
  }
103
118
  return entered
104
119
  }
105
120
  leave(entered: Map<AZone<unknown>, unknown>): void {
106
- for (const z of this.#zones) z.leave(entered.get(z))
121
+ for (const z of this.#zones) isu(z).leave(entered.get(z))
107
122
  }
108
123
  add(z: AZone<unknown>) {
109
124
  this.#zones.add(z)
@@ -116,12 +131,12 @@ export class ZoneAggregator extends AZone<Map<AZone<unknown>, unknown>> {
116
131
  }
117
132
  }
118
133
 
119
- export const asyncZone = tag(new ZoneAggregator(), 'async')
134
+ export const asyncZone = tag('async', new ZoneAggregator())
120
135
  asyncHooks.addHook(() => {
121
136
  const zone = asyncZone.active
122
137
  return () => {
123
138
  const prev = asyncZone.active
124
139
  asyncZone.active = zone
125
- return () => asyncZone.active = prev
140
+ return () => (asyncZone.active = prev)
126
141
  }
127
142
  })
package/dist/browser.js DELETED
@@ -1,161 +0,0 @@
1
- 'use strict';
2
-
3
- var index = require('./chunks/index-BFYK02LG.js');
4
-
5
- const hooks = new Set();
6
- index.asyncHooks.addHook = function (hook) {
7
- hooks.add(hook);
8
- return () => {
9
- hooks.delete(hook);
10
- };
11
- };
12
- function wrap(fn) {
13
- if (typeof fn !== 'function')
14
- return fn;
15
- const restorers = new Set();
16
- for (const hook of hooks)
17
- restorers.add(hook());
18
- return function (...args) {
19
- const undoers = new Set();
20
- for (const restore of restorers)
21
- undoers.add(restore());
22
- try {
23
- return fn.apply(this, args);
24
- }
25
- finally {
26
- for (const undo of undoers)
27
- undo();
28
- }
29
- };
30
- }
31
- const originals = {
32
- then: Promise.prototype.then,
33
- catch: Promise.prototype.catch,
34
- finally: Promise.prototype.finally,
35
- setTimeout: globalThis.setTimeout,
36
- setInterval: globalThis.setInterval,
37
- setImmediate: globalThis.setImmediate,
38
- requestAnimationFrame: globalThis.requestAnimationFrame,
39
- queueMicrotask: globalThis.queueMicrotask,
40
- };
41
- Promise.prototype.then = function (onFulfilled, onRejected) {
42
- return originals.then.call(this, wrap(onFulfilled), wrap(onRejected));
43
- };
44
- Promise.prototype.catch = function (onRejected) {
45
- return originals.catch.call(this, wrap(onRejected));
46
- };
47
- Promise.prototype.finally = function (onFinally) {
48
- return originals.finally.call(this, wrap(onFinally));
49
- };
50
- globalThis.setTimeout = ((callback, ...args) => {
51
- return originals.setTimeout.call(globalThis, wrap(callback), ...args);
52
- });
53
- globalThis.setInterval = ((callback, ...args) => {
54
- return originals.setInterval.call(globalThis, wrap(callback), ...args);
55
- });
56
- if (originals.setImmediate) {
57
- globalThis.setImmediate = ((callback, ...args) => {
58
- return originals.setImmediate.call(globalThis, wrap(callback), ...args);
59
- });
60
- }
61
- if (originals.requestAnimationFrame) {
62
- globalThis.requestAnimationFrame = (callback) => {
63
- return originals.requestAnimationFrame.call(globalThis, wrap(callback));
64
- };
65
- }
66
- if (originals.queueMicrotask) {
67
- globalThis.queueMicrotask = (callback) => {
68
- originals.queueMicrotask.call(globalThis, wrap(callback));
69
- };
70
- }
71
-
72
- exports.AZone = index.AZone;
73
- exports.ArrayReadForward = index.ArrayReadForward;
74
- exports.DecoratorError = index.DecoratorError;
75
- exports.Destroyable = index.Destroyable;
76
- exports.DestructionError = index.DestructionError;
77
- exports.Eventful = index.Eventful;
78
- exports.FoolProof = index.FoolProof;
79
- exports.Indexable = index.Indexable;
80
- exports.IterableWeakMap = index.IterableWeakMap;
81
- exports.IterableWeakSet = index.IterableWeakSet;
82
- exports.ReactiveBase = index.ReactiveBase;
83
- exports.ReactiveError = index.ReactiveError;
84
- Object.defineProperty(exports, "ReactiveErrorCode", {
85
- enumerable: true,
86
- get: function () { return index.ReactiveErrorCode; }
87
- });
88
- exports.Register = index.Register;
89
- exports.Zone = index.Zone;
90
- exports.ZoneAggregator = index.ZoneAggregator;
91
- exports.ZoneHistory = index.ZoneHistory;
92
- exports.addBatchCleanup = index.addBatchCleanup;
93
- exports.allocated = index.allocated;
94
- exports.allocatedValues = index.allocatedValues;
95
- exports.arrayEquals = index.arrayEquals;
96
- exports.asyncZone = index.asyncZone;
97
- exports.atomic = index.atomic;
98
- exports.biDi = index.biDi;
99
- exports.buildReactivityGraph = index.buildReactivityGraph;
100
- exports.cache = index.cache;
101
- exports.cached = index.cached;
102
- exports.callOnGC = index.callOnGC;
103
- exports.chainPromise = index.chainPromise;
104
- exports.cleanedBy = index.cleanedBy;
105
- exports.cleanup = index.cleanup;
106
- exports.contentRef = index.contentRef;
107
- exports.debounce = index.debounce;
108
- exports.decorator = index.decorator;
109
- exports.deepCompare = index.deepCompare;
110
- exports.deepWatch = index.deepWatch;
111
- exports.defer = index.defer;
112
- exports.deprecated = index.deprecated;
113
- exports.derived = index.derived;
114
- exports.describe = index.describe;
115
- exports.destructor = index.destructor;
116
- exports.effect = index.effect;
117
- exports.enableDevTools = index.enableDevTools;
118
- exports.forwardArray = index.forwardArray;
119
- exports.getActivationLog = index.getActivationLog;
120
- exports.getActiveProjection = index.getActiveProjection;
121
- exports.getAt = index.getAt;
122
- exports.getState = index.getState;
123
- exports.immutables = index.immutables;
124
- exports.isCached = index.isCached;
125
- exports.isConstructor = index.isConstructor;
126
- exports.isDevtoolsEnabled = index.isDevtoolsEnabled;
127
- exports.isNonReactive = index.isNonReactive;
128
- exports.isOwnAccessor = index.isOwnAccessor;
129
- exports.isReactive = index.isReactive;
130
- exports.legacyDecorator = index.legacyDecorator;
131
- exports.memoize = index.memoize;
132
- exports.mixin = index.mixin;
133
- exports.modernDecorator = index.modernDecorator;
134
- exports.named = index.named;
135
- exports.organize = index.organize;
136
- exports.organized = index.organized;
137
- exports.profileInfo = index.profileInfo;
138
- exports.project = index.project;
139
- exports.reactive = index.reactive;
140
- exports.reactiveOptions = index.options;
141
- exports.register = index.register;
142
- exports.registerEffectForDebug = index.registerEffectForDebug;
143
- exports.registerNativeReactivity = index.registerNativeReactivity;
144
- exports.registerObjectForDebug = index.registerObjectForDebug;
145
- exports.renamed = index.renamed;
146
- exports.root = index.root;
147
- exports.scan = index.scan;
148
- exports.setAt = index.setAt;
149
- exports.setEffectName = index.setEffectName;
150
- exports.setObjectName = index.setObjectName;
151
- exports.tag = index.tag;
152
- exports.throttle = index.throttle;
153
- exports.touched = index.touched;
154
- exports.touched1 = index.touched1;
155
- exports.trackEffect = index.trackEffect;
156
- exports.unreactive = index.unreactive;
157
- exports.untracked = index.untracked;
158
- exports.unwrap = index.unwrap;
159
- exports.watch = index.watch;
160
- exports.zip = index.zip;
161
- //# sourceMappingURL=browser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"browser.js","sources":["../src/async/browser.ts"],"sourcesContent":["import { Hook, Restorer, asyncHooks } from '.'\n\nconst hooks = new Set<Hook>()\n\nasyncHooks.addHook = function (hook: Hook) {\n\thooks.add(hook)\n\treturn () => {\n\t\thooks.delete(hook)\n\t}\n}\n\nexport * from '../index'\n\nfunction wrap<Args extends any[], R>(fn: ((...args: Args) => R) | null | undefined) {\n\tif (typeof fn !== 'function') return fn\n\tconst restorers = new Set<Restorer>()\n\tfor (const hook of hooks) restorers.add(hook())\n\n\treturn function (this: any, ...args: Args) {\n\t\tconst undoers = new Set<() => void>()\n\t\tfor (const restore of restorers) undoers.add(restore())\n\t\ttry {\n\t\t\treturn fn.apply(this, args)\n\t\t} finally {\n\t\t\tfor (const undo of undoers) undo()\n\t\t}\n\t}\n}\n\nconst originals = {\n\tthen: Promise.prototype.then,\n\tcatch: Promise.prototype.catch,\n\tfinally: Promise.prototype.finally,\n\tsetTimeout: globalThis.setTimeout,\n\tsetInterval: globalThis.setInterval,\n\tsetImmediate: globalThis.setImmediate,\n\trequestAnimationFrame: globalThis.requestAnimationFrame,\n\tqueueMicrotask: globalThis.queueMicrotask,\n}\n\nPromise.prototype.then = function <T, R1, R2>(\n\tthis: Promise<T>,\n\tonFulfilled?: ((value: T) => R1 | PromiseLike<R1>) | null,\n\tonRejected?: ((reason: any) => R2 | PromiseLike<R2>) | null\n): Promise<R1 | R2> {\n\treturn originals.then.call(this, wrap(onFulfilled), wrap(onRejected))\n}\n\nPromise.prototype.catch = function <T>(\n\tthis: Promise<T>,\n\tonRejected?: ((reason: any) => T | PromiseLike<T>) | null\n): Promise<T> {\n\treturn originals.catch.call(this, wrap(onRejected))\n}\n\nPromise.prototype.finally = function <T>(\n\tthis: Promise<T>,\n\tonFinally?: (() => void) | null\n): Promise<T> {\n\treturn originals.finally.call(this, wrap(onFinally))\n}\n\nglobalThis.setTimeout = ((callback: Function, ...args: any[]) => {\n\treturn originals.setTimeout.call(globalThis, wrap(callback as any), ...args)\n}) as any\n\nglobalThis.setInterval = ((callback: Function, ...args: any[]) => {\n\treturn originals.setInterval.call(globalThis, wrap(callback as any), ...args)\n}) as any\n\nif (originals.setImmediate) {\n\tglobalThis.setImmediate = ((callback: Function, ...args: any[]) => {\n\t\treturn originals.setImmediate.call(globalThis, wrap(callback as any), ...args)\n\t}) as any\n}\n\nif (originals.requestAnimationFrame) {\n\tglobalThis.requestAnimationFrame = (callback: FrameRequestCallback) => {\n\t\treturn originals.requestAnimationFrame.call(globalThis, wrap(callback))\n\t}\n}\n\nif (originals.queueMicrotask) {\n\tglobalThis.queueMicrotask = (callback: VoidFunction): void => {\n\t\toriginals.queueMicrotask.call(globalThis, wrap(callback))\n\t}\n}"],"names":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