@yiin/reactive-proxy-state 1.0.36 → 1.0.37
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 +55 -32
- package/dist/index.js +55 -32
- package/dist/integrations/vue3.d.ts +11 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4039,6 +4039,7 @@ function trackVueReactiveEvents(vueState, emit, options = {}) {
|
|
|
4039
4039
|
const prev = {};
|
|
4040
4040
|
const pathStack = [];
|
|
4041
4041
|
const keyStops = new Map;
|
|
4042
|
+
let rootStop = null;
|
|
4042
4043
|
for (const k of Object.keys(vueState)) {
|
|
4043
4044
|
prev[k] = deepClone(vueState[k]);
|
|
4044
4045
|
}
|
|
@@ -4066,41 +4067,63 @@ function trackVueReactiveEvents(vueState, emit, options = {}) {
|
|
|
4066
4067
|
}, { flush: "sync" });
|
|
4067
4068
|
keyStops.set(k, stop);
|
|
4068
4069
|
}
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4070
|
+
function createRootEffect() {
|
|
4071
|
+
rootStop = import_vue.watchEffect(() => {
|
|
4072
|
+
const currKeys = Object.keys(vueState);
|
|
4073
|
+
const currKeySet = new Set(currKeys);
|
|
4074
|
+
const prevKeySet = new Set(Object.keys(prev));
|
|
4075
|
+
for (const k of currKeys) {
|
|
4076
|
+
if (!prevKeySet.has(k)) {
|
|
4077
|
+
import_reactivity.pauseTracking();
|
|
4078
|
+
const cloned = deepClone(vueState[k]);
|
|
4079
|
+
import_reactivity.resetTracking();
|
|
4080
|
+
pathStack.push(k);
|
|
4081
|
+
emit({ action: "set", path: pathStack.slice(), newValue: cloned });
|
|
4082
|
+
pathStack.pop();
|
|
4083
|
+
prev[k] = cloned;
|
|
4084
|
+
createKeyEffect(k);
|
|
4085
|
+
}
|
|
4086
|
+
}
|
|
4087
|
+
for (const k of prevKeySet) {
|
|
4088
|
+
if (!currKeySet.has(k)) {
|
|
4089
|
+
pathStack.push(k);
|
|
4090
|
+
emit({ action: "delete", path: pathStack.slice(), oldValue: prev[k] });
|
|
4091
|
+
pathStack.pop();
|
|
4092
|
+
delete prev[k];
|
|
4093
|
+
keyStops.get(k)?.();
|
|
4094
|
+
keyStops.delete(k);
|
|
4095
|
+
}
|
|
4096
|
+
}
|
|
4097
|
+
}, { flush: "sync" });
|
|
4098
|
+
}
|
|
4099
|
+
function stopAll() {
|
|
4100
|
+
rootStop?.();
|
|
4101
|
+
rootStop = null;
|
|
4101
4102
|
for (const stop of keyStops.values())
|
|
4102
4103
|
stop();
|
|
4103
4104
|
keyStops.clear();
|
|
4105
|
+
}
|
|
4106
|
+
function startAll() {
|
|
4107
|
+
for (const k of Object.keys(prev)) {
|
|
4108
|
+
createKeyEffect(k);
|
|
4109
|
+
}
|
|
4110
|
+
createRootEffect();
|
|
4111
|
+
}
|
|
4112
|
+
startAll();
|
|
4113
|
+
return {
|
|
4114
|
+
stop: stopAll,
|
|
4115
|
+
pause: stopAll,
|
|
4116
|
+
resume() {
|
|
4117
|
+
const currentKeys = new Set(Object.keys(vueState));
|
|
4118
|
+
for (const k of Object.keys(prev)) {
|
|
4119
|
+
if (!currentKeys.has(k))
|
|
4120
|
+
delete prev[k];
|
|
4121
|
+
}
|
|
4122
|
+
for (const k of currentKeys) {
|
|
4123
|
+
prev[k] = deepClone(vueState[k]);
|
|
4124
|
+
}
|
|
4125
|
+
startAll();
|
|
4126
|
+
}
|
|
4104
4127
|
};
|
|
4105
4128
|
}
|
|
4106
4129
|
function typeTag(v) {
|
package/dist/index.js
CHANGED
|
@@ -3979,6 +3979,7 @@ function trackVueReactiveEvents(vueState, emit, options = {}) {
|
|
|
3979
3979
|
const prev = {};
|
|
3980
3980
|
const pathStack = [];
|
|
3981
3981
|
const keyStops = new Map;
|
|
3982
|
+
let rootStop = null;
|
|
3982
3983
|
for (const k of Object.keys(vueState)) {
|
|
3983
3984
|
prev[k] = deepClone(vueState[k]);
|
|
3984
3985
|
}
|
|
@@ -4006,41 +4007,63 @@ function trackVueReactiveEvents(vueState, emit, options = {}) {
|
|
|
4006
4007
|
}, { flush: "sync" });
|
|
4007
4008
|
keyStops.set(k, stop);
|
|
4008
4009
|
}
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4010
|
+
function createRootEffect() {
|
|
4011
|
+
rootStop = watchEffect2(() => {
|
|
4012
|
+
const currKeys = Object.keys(vueState);
|
|
4013
|
+
const currKeySet = new Set(currKeys);
|
|
4014
|
+
const prevKeySet = new Set(Object.keys(prev));
|
|
4015
|
+
for (const k of currKeys) {
|
|
4016
|
+
if (!prevKeySet.has(k)) {
|
|
4017
|
+
import_reactivity.pauseTracking();
|
|
4018
|
+
const cloned = deepClone(vueState[k]);
|
|
4019
|
+
import_reactivity.resetTracking();
|
|
4020
|
+
pathStack.push(k);
|
|
4021
|
+
emit({ action: "set", path: pathStack.slice(), newValue: cloned });
|
|
4022
|
+
pathStack.pop();
|
|
4023
|
+
prev[k] = cloned;
|
|
4024
|
+
createKeyEffect(k);
|
|
4025
|
+
}
|
|
4026
|
+
}
|
|
4027
|
+
for (const k of prevKeySet) {
|
|
4028
|
+
if (!currKeySet.has(k)) {
|
|
4029
|
+
pathStack.push(k);
|
|
4030
|
+
emit({ action: "delete", path: pathStack.slice(), oldValue: prev[k] });
|
|
4031
|
+
pathStack.pop();
|
|
4032
|
+
delete prev[k];
|
|
4033
|
+
keyStops.get(k)?.();
|
|
4034
|
+
keyStops.delete(k);
|
|
4035
|
+
}
|
|
4036
|
+
}
|
|
4037
|
+
}, { flush: "sync" });
|
|
4038
|
+
}
|
|
4039
|
+
function stopAll() {
|
|
4040
|
+
rootStop?.();
|
|
4041
|
+
rootStop = null;
|
|
4041
4042
|
for (const stop of keyStops.values())
|
|
4042
4043
|
stop();
|
|
4043
4044
|
keyStops.clear();
|
|
4045
|
+
}
|
|
4046
|
+
function startAll() {
|
|
4047
|
+
for (const k of Object.keys(prev)) {
|
|
4048
|
+
createKeyEffect(k);
|
|
4049
|
+
}
|
|
4050
|
+
createRootEffect();
|
|
4051
|
+
}
|
|
4052
|
+
startAll();
|
|
4053
|
+
return {
|
|
4054
|
+
stop: stopAll,
|
|
4055
|
+
pause: stopAll,
|
|
4056
|
+
resume() {
|
|
4057
|
+
const currentKeys = new Set(Object.keys(vueState));
|
|
4058
|
+
for (const k of Object.keys(prev)) {
|
|
4059
|
+
if (!currentKeys.has(k))
|
|
4060
|
+
delete prev[k];
|
|
4061
|
+
}
|
|
4062
|
+
for (const k of currentKeys) {
|
|
4063
|
+
prev[k] = deepClone(vueState[k]);
|
|
4064
|
+
}
|
|
4065
|
+
startAll();
|
|
4066
|
+
}
|
|
4044
4067
|
};
|
|
4045
4068
|
}
|
|
4046
4069
|
function typeTag(v) {
|
|
@@ -8,6 +8,14 @@ export type TrackVueReactiveEventsOptions = {
|
|
|
8
8
|
emitInitialReplace?: boolean;
|
|
9
9
|
onDiffError?: (ctx: DiffErrorContext) => void;
|
|
10
10
|
};
|
|
11
|
+
export type VueTrackingControl = {
|
|
12
|
+
/** Stop all effects permanently. */
|
|
13
|
+
stop: () => void;
|
|
14
|
+
/** Stop all effects temporarily. No diffing overhead while paused. */
|
|
15
|
+
pause: () => void;
|
|
16
|
+
/** Rebuild snapshots from current state and re-create effects. */
|
|
17
|
+
resume: () => void;
|
|
18
|
+
};
|
|
11
19
|
/**
|
|
12
20
|
* Observe a Vue 3 reactive object and emit RPS-compatible StateEvents
|
|
13
21
|
* for each mutation performed through Vue reactivity.
|
|
@@ -16,6 +24,7 @@ export type TrackVueReactiveEventsOptions = {
|
|
|
16
24
|
* only the affected subtree is diffed on mutation. A root structural effect
|
|
17
25
|
* tracks Object.keys() for key add/delete at the top level.
|
|
18
26
|
*
|
|
19
|
-
* Returns a
|
|
27
|
+
* Returns a control object with stop/pause/resume. Use pause/resume to
|
|
28
|
+
* suppress diffing while applying external mutations (e.g. server events).
|
|
20
29
|
*/
|
|
21
|
-
export declare function trackVueReactiveEvents<T extends object>(vueState: T, emit: (event: StateEvent) => void, options?: TrackVueReactiveEventsOptions):
|
|
30
|
+
export declare function trackVueReactiveEvents<T extends object>(vueState: T, emit: (event: StateEvent) => void, options?: TrackVueReactiveEventsOptions): VueTrackingControl;
|