mutts 1.0.3 → 1.0.4
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/chunks/{index-DzUDtFc7.esm.js → index-79Kk8D6e.esm.js} +67 -51
- package/dist/chunks/index-79Kk8D6e.esm.js.map +1 -0
- package/dist/chunks/{index-HNVqPzjz.js → index-GRBSx0mB.js} +67 -50
- package/dist/chunks/index-GRBSx0mB.js.map +1 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- 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/reactive.d.ts +2 -1
- package/dist/reactive.esm.js +1 -1
- package/dist/reactive.js +2 -1
- package/dist/reactive.js.map +1 -1
- package/package.json +1 -1
- package/src/reactive/effects.ts +63 -51
- package/src/reactive/index.ts +1 -0
- package/src/reactive/proxy.ts +5 -1
- package/dist/chunks/index-DzUDtFc7.esm.js.map +0 -1
- package/dist/chunks/index-HNVqPzjz.js.map +0 -1
package/dist/reactive.d.ts
CHANGED
|
@@ -470,6 +470,7 @@ declare function addBatchCleanup(cleanup: ScopedCallback): void;
|
|
|
470
470
|
* ```
|
|
471
471
|
*/
|
|
472
472
|
declare const defer: typeof addBatchCleanup;
|
|
473
|
+
declare function batch(effect: ScopedCallback | ScopedCallback[], immediate?: 'immediate'): any;
|
|
473
474
|
/**
|
|
474
475
|
* Decorator that makes methods atomic - batches all effects triggered within the method
|
|
475
476
|
*/
|
|
@@ -852,5 +853,5 @@ declare function isZoneEnabled(): boolean;
|
|
|
852
853
|
*/
|
|
853
854
|
declare const profileInfo: any;
|
|
854
855
|
|
|
855
|
-
export { ReactiveBase, ReactiveError, ReadOnlyError, Register, addBatchCleanup, atomic, biDi, buildReactivityGraph, cleanedBy, cleanup, deepWatch, defer, derived, effect, enableDevTools, getActiveEffect, getState, immutables, isDevtoolsEnabled, isNonReactive, isReactive, isZoneEnabled, mapped, memoize, organize, organized, profileInfo, project, reactive, options as reactiveOptions, reduced, register, registerEffectForDebug, registerNativeReactivity, registerObjectForDebug, root, setEffectName, setObjectName, setZoneEnabled, touched, touched1, trackEffect, unreactive, untracked, unwrap, watch };
|
|
856
|
+
export { ReactiveBase, ReactiveError, ReadOnlyError, Register, addBatchCleanup, atomic, batch, biDi, buildReactivityGraph, cleanedBy, cleanup, deepWatch, defer, derived, effect, enableDevTools, getActiveEffect, getState, immutables, isDevtoolsEnabled, isNonReactive, isReactive, isZoneEnabled, mapped, memoize, organize, organized, profileInfo, project, reactive, options as reactiveOptions, reduced, register, registerEffectForDebug, registerNativeReactivity, registerObjectForDebug, root, setEffectName, setObjectName, setZoneEnabled, touched, touched1, trackEffect, unreactive, untracked, unwrap, watch };
|
|
856
857
|
export type { DependencyAccess, DependencyFunction, Evolution, Memoizable, ReactivityGraph, ScopedCallback };
|
package/dist/reactive.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { M as ReactiveBase, V as ReactiveError, R as ReadOnlyError, S as Register, j as addBatchCleanup, k as atomic, l as batch, n as biDi, c as buildReactivityGraph, y as cleanedBy, z as cleanup, h as deepWatch, o as defer, A as derived, q as effect, e as enableDevTools, u as getActiveEffect, g as getState, G as immutables, i as isDevtoolsEnabled, H as isNonReactive, L as isReactive, W as isZoneEnabled, D as mapped, F as memoize, P as organize, Q as organized, p as profileInfo, K as project, N as reactive, U as reactiveOptions, E as reduced, T as register, r as registerEffectForDebug, J as registerNativeReactivity, d as registerObjectForDebug, v as root, s as setEffectName, f as setObjectName, X as setZoneEnabled, t as touched, b as touched1, w as trackEffect, B as unreactive, x as untracked, O as unwrap, C as watch } from './chunks/index-79Kk8D6e.esm.js';
|
|
2
2
|
import './chunks/decorator-DqiszP7i.esm.js';
|
|
3
3
|
import './indexable.esm.js';
|
|
4
4
|
import './chunks/_tslib-Mzh1rNsX.esm.js';
|
package/dist/reactive.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var reactive = require('./chunks/index-
|
|
3
|
+
var reactive = require('./chunks/index-GRBSx0mB.js');
|
|
4
4
|
require('./chunks/decorator-DLvrD0UF.js');
|
|
5
5
|
require('./indexable.js');
|
|
6
6
|
require('./chunks/_tslib-BgjropY9.js');
|
|
@@ -13,6 +13,7 @@ exports.ReadOnlyError = reactive.ReadOnlyError;
|
|
|
13
13
|
exports.Register = reactive.Register;
|
|
14
14
|
exports.addBatchCleanup = reactive.addBatchCleanup;
|
|
15
15
|
exports.atomic = reactive.atomic;
|
|
16
|
+
exports.batch = reactive.batch;
|
|
16
17
|
exports.biDi = reactive.biDi;
|
|
17
18
|
exports.buildReactivityGraph = reactive.buildReactivityGraph;
|
|
18
19
|
exports.cleanedBy = reactive.cleanedBy;
|
package/dist/reactive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactive.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reactive.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
package/src/reactive/effects.ts
CHANGED
|
@@ -835,15 +835,18 @@ export function batch(effect: ScopedCallback | ScopedCallback[], immediate?: 'im
|
|
|
835
835
|
addToBatch(effect[i], caller, immediate === 'immediate')
|
|
836
836
|
}
|
|
837
837
|
if (immediate) {
|
|
838
|
+
const firstReturn: { value?: any } = {}
|
|
838
839
|
// Execute immediately (before batch returns)
|
|
839
840
|
for (let i = 0; i < effect.length; i++) {
|
|
840
841
|
try {
|
|
841
|
-
effect[i]()
|
|
842
|
+
const rv = effect[i]()
|
|
843
|
+
if (rv !== undefined && !('value' in firstReturn)) firstReturn.value = rv
|
|
842
844
|
} finally {
|
|
843
845
|
const root = getRoot(effect[i])
|
|
844
846
|
batchQueue.all.delete(root)
|
|
845
847
|
}
|
|
846
848
|
}
|
|
849
|
+
return firstReturn.value
|
|
847
850
|
}
|
|
848
851
|
// Otherwise, effects will be picked up in next executeNext() call
|
|
849
852
|
} else {
|
|
@@ -935,67 +938,76 @@ export function batch(effect: ScopedCallback | ScopedCallback[], immediate?: 'im
|
|
|
935
938
|
// Execute in dependency order
|
|
936
939
|
const firstReturn: { value?: any } = {}
|
|
937
940
|
try {
|
|
938
|
-
while
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
941
|
+
// Outer loop: continue while there are effects OR cleanups pending.
|
|
942
|
+
// This ensures effects triggered by cleanups are not lost.
|
|
943
|
+
while (batchQueue.all.size > 0 || batchCleanups.size > 0) {
|
|
944
|
+
// Inner loop: execute all pending effects
|
|
945
|
+
while (batchQueue.all.size > 0) {
|
|
946
|
+
if (effectuatedRoots.length > options.maxEffectChain) {
|
|
947
|
+
const cycle = findCycleInChain(effectuatedRoots as any)
|
|
948
|
+
const trace = formatRoots(effectuatedRoots as any)
|
|
949
|
+
const message = cycle
|
|
950
|
+
? `Max effect chain reached (cycle detected: ${formatRoots(cycle)})`
|
|
951
|
+
: `Max effect chain reached (trace: ${trace})`
|
|
952
|
+
|
|
953
|
+
const queuedRoots = batchQueue ? Array.from(batchQueue.all.keys()) : []
|
|
954
|
+
const queued = queuedRoots.map((r) => r.name || '<anonymous>')
|
|
955
|
+
const debugInfo = {
|
|
956
|
+
code: ReactiveErrorCode.MaxDepthExceeded,
|
|
957
|
+
effectuatedRoots,
|
|
958
|
+
cycle,
|
|
959
|
+
trace,
|
|
960
|
+
maxEffectChain: options.maxEffectChain,
|
|
961
|
+
queued: queued.slice(0, 50),
|
|
962
|
+
queuedCount: queued.length,
|
|
963
|
+
// Try to get causation for the last effect
|
|
964
|
+
causalChain:
|
|
965
|
+
effectuatedRoots.length > 0
|
|
966
|
+
? getTriggerChain(
|
|
967
|
+
batchQueue.all.get(effectuatedRoots[effectuatedRoots.length - 1])!
|
|
968
|
+
)
|
|
969
|
+
: [],
|
|
970
|
+
}
|
|
971
|
+
switch (options.maxEffectReaction) {
|
|
972
|
+
case 'throw':
|
|
973
|
+
throw new ReactiveError(`[reactive] ${message}`, debugInfo)
|
|
974
|
+
case 'debug':
|
|
975
|
+
// biome-ignore lint/suspicious/noDebugger: This is the whole point here
|
|
976
|
+
debugger
|
|
977
|
+
throw new ReactiveError(`[reactive] ${message}`, debugInfo)
|
|
978
|
+
case 'warn':
|
|
979
|
+
options.warn(
|
|
980
|
+
`[reactive] ${message} (queued: ${queued.slice(0, 10).join(', ')}${queued.length > 10 ? ', …' : ''})`
|
|
981
|
+
)
|
|
982
|
+
break
|
|
983
|
+
}
|
|
963
984
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
throw new ReactiveError(`[reactive] ${message}`, debugInfo)
|
|
971
|
-
case 'warn':
|
|
972
|
-
options.warn(
|
|
973
|
-
`[reactive] ${message} (queued: ${queued.slice(0, 10).join(', ')}${queued.length > 10 ? ', …' : ''})`
|
|
974
|
-
)
|
|
975
|
-
break
|
|
985
|
+
const rv = executeNext(effectuatedRoots)
|
|
986
|
+
// executeNext() returns null when batch is complete or cycle detected (throws error)
|
|
987
|
+
// But functions can legitimately return null, so we check batchQueue.all.size instead
|
|
988
|
+
if (batchQueue.all.size === 0) {
|
|
989
|
+
// Batch complete
|
|
990
|
+
break
|
|
976
991
|
}
|
|
992
|
+
// If executeNext() returned null but batch is not empty, it means a cycle was detected
|
|
993
|
+
// and an error was thrown, so we won't reach here
|
|
994
|
+
if (rv !== undefined && !('value' in firstReturn)) firstReturn.value = rv
|
|
995
|
+
// Note: executeNext() already removed it from batchQueue, so we track by count
|
|
977
996
|
}
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
break
|
|
997
|
+
// Process cleanups. If they trigger new effects, the outer loop will catch them.
|
|
998
|
+
if (batchCleanups.size > 0) {
|
|
999
|
+
const cleanups = Array.from(batchCleanups)
|
|
1000
|
+
batchCleanups.clear()
|
|
1001
|
+
for (const cleanup of cleanups) cleanup()
|
|
984
1002
|
}
|
|
985
|
-
// If executeNext() returned null but batch is not empty, it means a cycle was detected
|
|
986
|
-
// and an error was thrown, so we won't reach here
|
|
987
|
-
if (rv !== undefined && !('value' in firstReturn)) firstReturn.value = rv
|
|
988
|
-
// Note: executeNext() already removed it from batchQueue, so we track by count
|
|
989
1003
|
}
|
|
990
|
-
const cleanups = Array.from(batchCleanups)
|
|
991
|
-
batchCleanups.clear()
|
|
992
|
-
for (const cleanup of cleanups) cleanup()
|
|
993
1004
|
return firstReturn.value
|
|
994
1005
|
} finally {
|
|
995
1006
|
batchQueue = undefined
|
|
996
1007
|
options.endChain()
|
|
997
1008
|
}
|
|
998
1009
|
}
|
|
1010
|
+
|
|
999
1011
|
}
|
|
1000
1012
|
}
|
|
1001
1013
|
|
package/src/reactive/index.ts
CHANGED
package/src/reactive/proxy.ts
CHANGED
|
@@ -79,7 +79,11 @@ const reactiveHandlers = {
|
|
|
79
79
|
while (current && current !== Object.prototype) {
|
|
80
80
|
dependant(current, prop)
|
|
81
81
|
if (Object.hasOwn(current, prop)) break
|
|
82
|
-
|
|
82
|
+
let next = reactiveObject(Object.getPrototypeOf(current))
|
|
83
|
+
if (next === current) {
|
|
84
|
+
next = reactiveObject(Object.getPrototypeOf(unwrap(current)))
|
|
85
|
+
}
|
|
86
|
+
current = next
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
89
|
const value = ReflectGet(obj, prop, receiver)
|