mutts 1.0.5 → 1.0.7
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/README.md +2 -1
- package/dist/browser.d.ts +2 -0
- package/dist/browser.esm.js +70 -0
- package/dist/browser.esm.js.map +1 -0
- package/dist/browser.js +161 -0
- package/dist/browser.js.map +1 -0
- package/dist/chunks/{index-Cvxdw6Ax.js → index-BFYK02LG.js} +5377 -4059
- package/dist/chunks/index-BFYK02LG.js.map +1 -0
- package/dist/chunks/{index-qiWwozOc.esm.js → index-CNR6QRUl.esm.js} +5247 -3963
- package/dist/chunks/index-CNR6QRUl.esm.js.map +1 -0
- package/dist/mutts.umd.js +1 -1
- package/dist/mutts.umd.js.map +1 -1
- package/dist/mutts.umd.min.js +1 -1
- package/dist/mutts.umd.min.js.map +1 -1
- package/dist/node.d.ts +2 -0
- package/dist/node.esm.js +45 -0
- package/dist/node.esm.js.map +1 -0
- package/dist/node.js +136 -0
- package/dist/node.js.map +1 -0
- package/docs/ai/api-reference.md +0 -2
- package/docs/ai/manual.md +14 -95
- package/docs/reactive/advanced.md +7 -111
- package/docs/reactive/collections.md +0 -125
- package/docs/reactive/core.md +27 -24
- package/docs/reactive/debugging.md +168 -0
- package/docs/reactive/project.md +1 -1
- package/docs/reactive/scan.md +78 -0
- package/docs/reactive.md +8 -6
- package/docs/std-decorators.md +1 -0
- package/docs/zone.md +88 -0
- package/package.json +47 -65
- package/src/async/browser.ts +87 -0
- package/src/async/index.ts +8 -0
- package/src/async/node.ts +46 -0
- package/src/decorator.ts +15 -9
- package/src/destroyable.ts +4 -4
- package/src/index.ts +54 -0
- package/src/indexable.ts +42 -0
- package/src/mixins.ts +2 -2
- package/src/reactive/array.ts +149 -141
- package/src/reactive/buffer.ts +168 -0
- package/src/reactive/change.ts +3 -3
- package/src/reactive/debug.ts +1 -1
- package/src/reactive/deep-touch.ts +1 -1
- package/src/reactive/deep-watch.ts +1 -1
- package/src/reactive/effect-context.ts +15 -91
- package/src/reactive/effects.ts +138 -170
- package/src/reactive/index.ts +10 -13
- package/src/reactive/interface.ts +20 -33
- package/src/reactive/map.ts +48 -61
- package/src/reactive/memoize.ts +87 -31
- package/src/reactive/project.ts +43 -22
- package/src/reactive/proxy.ts +18 -43
- package/src/reactive/record.ts +3 -3
- package/src/reactive/register.ts +5 -7
- package/src/reactive/registry.ts +59 -0
- package/src/reactive/set.ts +42 -56
- package/src/reactive/tracking.ts +5 -62
- package/src/reactive/types.ts +79 -19
- package/src/std-decorators.ts +9 -9
- package/src/utils.ts +203 -19
- package/src/zone.ts +127 -0
- package/dist/chunks/_tslib-BgjropY9.js +0 -81
- package/dist/chunks/_tslib-BgjropY9.js.map +0 -1
- package/dist/chunks/_tslib-Mzh1rNsX.esm.js +0 -75
- package/dist/chunks/_tslib-Mzh1rNsX.esm.js.map +0 -1
- package/dist/chunks/decorator-DLvrD0UF.js +0 -265
- package/dist/chunks/decorator-DLvrD0UF.js.map +0 -1
- package/dist/chunks/decorator-DqiszP7i.esm.js +0 -253
- package/dist/chunks/decorator-DqiszP7i.esm.js.map +0 -1
- package/dist/chunks/index-Cvxdw6Ax.js.map +0 -1
- package/dist/chunks/index-qiWwozOc.esm.js.map +0 -1
- package/dist/decorator.d.ts +0 -107
- package/dist/decorator.esm.js +0 -2
- package/dist/decorator.esm.js.map +0 -1
- package/dist/decorator.js +0 -11
- package/dist/decorator.js.map +0 -1
- package/dist/destroyable.d.ts +0 -90
- package/dist/destroyable.esm.js +0 -109
- package/dist/destroyable.esm.js.map +0 -1
- package/dist/destroyable.js +0 -116
- package/dist/destroyable.js.map +0 -1
- package/dist/eventful.d.ts +0 -20
- package/dist/eventful.esm.js +0 -66
- package/dist/eventful.esm.js.map +0 -1
- package/dist/eventful.js +0 -68
- package/dist/eventful.js.map +0 -1
- package/dist/index.d.ts +0 -19
- package/dist/index.esm.js +0 -8
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js +0 -95
- package/dist/index.js.map +0 -1
- package/dist/indexable.d.ts +0 -243
- package/dist/indexable.esm.js +0 -285
- package/dist/indexable.esm.js.map +0 -1
- package/dist/indexable.js +0 -291
- package/dist/indexable.js.map +0 -1
- package/dist/promiseChain.d.ts +0 -21
- package/dist/promiseChain.esm.js +0 -78
- package/dist/promiseChain.esm.js.map +0 -1
- package/dist/promiseChain.js +0 -80
- package/dist/promiseChain.js.map +0 -1
- package/dist/reactive.d.ts +0 -885
- package/dist/reactive.esm.js +0 -5
- package/dist/reactive.esm.js.map +0 -1
- package/dist/reactive.js +0 -59
- package/dist/reactive.js.map +0 -1
- package/dist/std-decorators.d.ts +0 -52
- package/dist/std-decorators.esm.js +0 -196
- package/dist/std-decorators.esm.js.map +0 -1
- package/dist/std-decorators.js +0 -204
- package/dist/std-decorators.js.map +0 -1
- package/src/reactive/mapped.ts +0 -129
- package/src/reactive/zone.ts +0 -208
package/src/reactive/change.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { bubbleUpChange, objectsWithDeepWatchers } from './deep-watch-state'
|
|
|
3
3
|
import { getActiveEffect, isRunning } from './effect-context'
|
|
4
4
|
import { batch, effectTrackers, hasBatched, opaqueEffects, recordActivation } from './effects'
|
|
5
5
|
import { unwrap } from './proxy-state'
|
|
6
|
-
import { watchers } from './
|
|
6
|
+
import { watchers } from './registry'
|
|
7
7
|
import { allProps, type Evolution, options, type ScopedCallback, type State } from './types'
|
|
8
8
|
|
|
9
9
|
const states = new WeakMap<object, State>()
|
|
@@ -46,7 +46,7 @@ export function collectEffects(
|
|
|
46
46
|
for (const effect of deps) {
|
|
47
47
|
const runningChain = isRunning(effect)
|
|
48
48
|
if (runningChain) {
|
|
49
|
-
options.skipRunningEffect(effect
|
|
49
|
+
options.skipRunningEffect(effect)
|
|
50
50
|
continue
|
|
51
51
|
}
|
|
52
52
|
if (!effects.has(effect)) {
|
|
@@ -118,7 +118,7 @@ export function touchedOpaque(obj: any, evolution: Evolution, prop: any) {
|
|
|
118
118
|
|
|
119
119
|
const runningChain = isRunning(effect)
|
|
120
120
|
if (runningChain) {
|
|
121
|
-
options.skipRunningEffect(effect
|
|
121
|
+
options.skipRunningEffect(effect)
|
|
122
122
|
continue
|
|
123
123
|
}
|
|
124
124
|
effects.add(effect)
|
package/src/reactive/debug.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* - Provides graph data for tooling (DevTools panel, etc.)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { effectParent, effectToReactiveObjects, getRoot } from './
|
|
8
|
+
import { effectParent, effectToReactiveObjects, getRoot } from './registry'
|
|
9
9
|
import { allProps, type Evolution, options, type ScopedCallback } from './types'
|
|
10
10
|
|
|
11
11
|
const EXTERNAL_SOURCE = Symbol('external-source')
|
|
@@ -3,7 +3,7 @@ import { bubbleUpChange, objectsWithDeepWatchers } from './deep-watch-state'
|
|
|
3
3
|
import { batch } from './effects'
|
|
4
4
|
import { isNonReactive } from './non-reactive-state'
|
|
5
5
|
import { unwrap } from './proxy-state'
|
|
6
|
-
import { effectParent, watchers } from './
|
|
6
|
+
import { effectParent, watchers } from './registry'
|
|
7
7
|
import { allProps, type Evolution, options, type ScopedCallback } from './types'
|
|
8
8
|
|
|
9
9
|
function isObject(value: any): value is object {
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
import { effect } from './effects'
|
|
7
7
|
import { isNonReactive } from './non-reactive-state'
|
|
8
8
|
import { reactive, unwrap } from './proxy'
|
|
9
|
-
import { markWithRoot } from './
|
|
9
|
+
import { markWithRoot } from './registry'
|
|
10
10
|
import { options, type ScopedCallback } from './types'
|
|
11
11
|
|
|
12
12
|
function isObject(value: any): value is object {
|
|
@@ -1,94 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const rootEffect = getRoot(effect)
|
|
15
|
-
|
|
16
|
-
// Check if the effect is directly in the stack
|
|
17
|
-
const rootIndex = stack.indexOf(rootEffect)
|
|
18
|
-
if (rootIndex !== -1) {
|
|
19
|
-
return stack.slice(0, rootIndex + 1).reverse()
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Check if any effect in the stack is a descendant of this effect
|
|
23
|
-
// (i.e., walk up the parent chain from each stack effect to see if we reach this effect)
|
|
24
|
-
for (let i = 0; i < stack.length; i++) {
|
|
25
|
-
const stackEffect = stack[i]
|
|
26
|
-
let current: ScopedCallback | undefined = stackEffect
|
|
27
|
-
const visited = new WeakSet<ScopedCallback>()
|
|
28
|
-
const ancestorChain: ScopedCallback[] = []
|
|
29
|
-
// TODO: That's perhaps a lot of computations for an `assert`
|
|
30
|
-
// Walk up the parent chain to find if this effect is an ancestor
|
|
31
|
-
while (current && !visited.has(current)) {
|
|
32
|
-
visited.add(current)
|
|
33
|
-
const currentRoot = getRoot(current)
|
|
34
|
-
ancestorChain.push(currentRoot)
|
|
35
|
-
if (currentRoot === rootEffect) {
|
|
36
|
-
// Found a descendant - build the full chain from ancestor to active
|
|
37
|
-
// The ancestorChain contains [descendant, parent, ..., ancestor] (walking up)
|
|
38
|
-
// We need [ancestor (effect), ..., parent, descendant, ...stack from descendant to active]
|
|
39
|
-
const chainFromAncestor = ancestorChain.reverse() // [ancestor, ..., descendant]
|
|
40
|
-
// Prepend the actual effect we're checking (in case current is a wrapper)
|
|
41
|
-
if (chainFromAncestor[0] !== rootEffect) {
|
|
42
|
-
chainFromAncestor.unshift(rootEffect)
|
|
43
|
-
}
|
|
44
|
-
// Append the rest of the stack from the descendant to the active effect
|
|
45
|
-
const stackFromDescendant = stack.slice(0, i + 1).reverse() // [descendant, ..., active]
|
|
46
|
-
// Remove duplicate descendant (it's both at end of chainFromAncestor and start of stackFromDescendant)
|
|
47
|
-
if (chainFromAncestor.length > 0 && stackFromDescendant.length > 0) {
|
|
48
|
-
stackFromDescendant.shift() // Remove duplicate descendant
|
|
49
|
-
}
|
|
50
|
-
return [...chainFromAncestor, ...stackFromDescendant]
|
|
51
|
-
}
|
|
52
|
-
current = effectParent.get(current)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return false
|
|
57
|
-
}
|
|
58
|
-
export function withEffectStack<T>(snapshot: (ScopedCallback | undefined)[], fn: () => T): T {
|
|
59
|
-
const previousStack = stack.slice()
|
|
60
|
-
assignStack(snapshot)
|
|
61
|
-
try {
|
|
62
|
-
return fn()
|
|
63
|
-
} finally {
|
|
64
|
-
assignStack(previousStack)
|
|
65
|
-
}
|
|
1
|
+
import { tag } from '../utils'
|
|
2
|
+
import { asyncZone, ZoneAggregator, ZoneHistory } from '../zone'
|
|
3
|
+
import { getRoot } from './registry'
|
|
4
|
+
import { type ScopedCallback } from './types'
|
|
5
|
+
|
|
6
|
+
export const effectHistory = tag(new ZoneHistory<ScopedCallback>(), 'effectHistory')
|
|
7
|
+
tag(effectHistory.present, 'effectHistory.present')
|
|
8
|
+
asyncZone.add(effectHistory)
|
|
9
|
+
export const effectAggregator = tag(new ZoneAggregator(effectHistory.present), 'effectAggregator')
|
|
10
|
+
|
|
11
|
+
export function isRunning(effect: ScopedCallback): boolean {
|
|
12
|
+
const root = getRoot(effect)
|
|
13
|
+
return effectHistory.some((e) => getRoot(e) === root)
|
|
66
14
|
}
|
|
67
15
|
|
|
68
16
|
export function getActiveEffect() {
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Executes a function with a specific effect context
|
|
74
|
-
* @param effect - The effect to use as context
|
|
75
|
-
* @param fn - The function to execute
|
|
76
|
-
* @param keepParent - Whether to keep the parent effect context
|
|
77
|
-
* @returns The result of the function
|
|
78
|
-
*/
|
|
79
|
-
export function withEffect<T>(effect: ScopedCallback | undefined, fn: () => T): T {
|
|
80
|
-
// console.log('[Mutts] withEffect', effect ? 'Active' : 'NULL');
|
|
81
|
-
if (getRoot(effect) === getRoot(getActiveEffect())) return fn()
|
|
82
|
-
stack.unshift(effect)
|
|
83
|
-
try {
|
|
84
|
-
return fn()
|
|
85
|
-
} finally {
|
|
86
|
-
const recoveredEffect = stack.shift()
|
|
87
|
-
if (recoveredEffect !== effect) throw new ReactiveError('[reactive] Effect stack mismatch')
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function assignStack(values: (ScopedCallback | undefined)[]) {
|
|
92
|
-
stack.length = 0
|
|
93
|
-
stack.push(...values)
|
|
94
|
-
}
|
|
17
|
+
return effectHistory.present.active
|
|
18
|
+
}
|