@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 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
- for (const k of Object.keys(prev)) {
4070
- createKeyEffect(k);
4071
- }
4072
- const stopRoot = import_vue.watchEffect(() => {
4073
- const currKeys = Object.keys(vueState);
4074
- const currKeySet = new Set(currKeys);
4075
- const prevKeySet = new Set(Object.keys(prev));
4076
- for (const k of currKeys) {
4077
- if (!prevKeySet.has(k)) {
4078
- import_reactivity.pauseTracking();
4079
- const cloned = deepClone(vueState[k]);
4080
- import_reactivity.resetTracking();
4081
- pathStack.push(k);
4082
- emit({ action: "set", path: pathStack.slice(), newValue: cloned });
4083
- pathStack.pop();
4084
- prev[k] = cloned;
4085
- createKeyEffect(k);
4086
- }
4087
- }
4088
- for (const k of prevKeySet) {
4089
- if (!currKeySet.has(k)) {
4090
- pathStack.push(k);
4091
- emit({ action: "delete", path: pathStack.slice(), oldValue: prev[k] });
4092
- pathStack.pop();
4093
- delete prev[k];
4094
- keyStops.get(k)?.();
4095
- keyStops.delete(k);
4096
- }
4097
- }
4098
- }, { flush: "sync" });
4099
- return () => {
4100
- stopRoot();
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
- for (const k of Object.keys(prev)) {
4010
- createKeyEffect(k);
4011
- }
4012
- const stopRoot = watchEffect2(() => {
4013
- const currKeys = Object.keys(vueState);
4014
- const currKeySet = new Set(currKeys);
4015
- const prevKeySet = new Set(Object.keys(prev));
4016
- for (const k of currKeys) {
4017
- if (!prevKeySet.has(k)) {
4018
- import_reactivity.pauseTracking();
4019
- const cloned = deepClone(vueState[k]);
4020
- import_reactivity.resetTracking();
4021
- pathStack.push(k);
4022
- emit({ action: "set", path: pathStack.slice(), newValue: cloned });
4023
- pathStack.pop();
4024
- prev[k] = cloned;
4025
- createKeyEffect(k);
4026
- }
4027
- }
4028
- for (const k of prevKeySet) {
4029
- if (!currKeySet.has(k)) {
4030
- pathStack.push(k);
4031
- emit({ action: "delete", path: pathStack.slice(), oldValue: prev[k] });
4032
- pathStack.pop();
4033
- delete prev[k];
4034
- keyStops.get(k)?.();
4035
- keyStops.delete(k);
4036
- }
4037
- }
4038
- }, { flush: "sync" });
4039
- return () => {
4040
- stopRoot();
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 stop() function to tear down all effects.
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): () => void;
30
+ export declare function trackVueReactiveEvents<T extends object>(vueState: T, emit: (event: StateEvent) => void, options?: TrackVueReactiveEventsOptions): VueTrackingControl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yiin/reactive-proxy-state",
3
- "version": "1.0.36",
3
+ "version": "1.0.37",
4
4
  "author": "Yiin <stanislovas@yiin.lt>",
5
5
  "repository": {
6
6
  "type": "git",