@coaction/history 1.2.0 → 1.4.0

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.js CHANGED
@@ -97,6 +97,18 @@ var isEqual = (a, b, visited = /* @__PURE__ */ new WeakMap()) => {
97
97
  }
98
98
  return true;
99
99
  };
100
+ var applySnapshot = (target, nextState, currentState) => {
101
+ const next = nextState;
102
+ const current = currentState;
103
+ for (const key of Object.keys(current)) {
104
+ if (!Object.prototype.hasOwnProperty.call(next, key)) {
105
+ delete target[key];
106
+ }
107
+ }
108
+ for (const key of Object.keys(next)) {
109
+ target[key] = toSnapshot(next[key]);
110
+ }
111
+ };
100
112
  var history = ({
101
113
  limit = 100,
102
114
  partialize = (state) => state
@@ -135,7 +147,13 @@ var history = ({
135
147
  future.push(current);
136
148
  isTimeTraveling = true;
137
149
  try {
138
- baseSetState(previous);
150
+ baseSetState((draft) => {
151
+ applySnapshot(
152
+ draft,
153
+ previous,
154
+ current
155
+ );
156
+ });
139
157
  } finally {
140
158
  isTimeTraveling = false;
141
159
  }
@@ -150,7 +168,13 @@ var history = ({
150
168
  past.push(current);
151
169
  isTimeTraveling = true;
152
170
  try {
153
- baseSetState(next);
171
+ baseSetState((draft) => {
172
+ applySnapshot(
173
+ draft,
174
+ next,
175
+ current
176
+ );
177
+ });
154
178
  } finally {
155
179
  isTimeTraveling = false;
156
180
  }
package/dist/index.mjs CHANGED
@@ -71,6 +71,18 @@ var isEqual = (a, b, visited = /* @__PURE__ */ new WeakMap()) => {
71
71
  }
72
72
  return true;
73
73
  };
74
+ var applySnapshot = (target, nextState, currentState) => {
75
+ const next = nextState;
76
+ const current = currentState;
77
+ for (const key of Object.keys(current)) {
78
+ if (!Object.prototype.hasOwnProperty.call(next, key)) {
79
+ delete target[key];
80
+ }
81
+ }
82
+ for (const key of Object.keys(next)) {
83
+ target[key] = toSnapshot(next[key]);
84
+ }
85
+ };
74
86
  var history = ({
75
87
  limit = 100,
76
88
  partialize = (state) => state
@@ -109,7 +121,13 @@ var history = ({
109
121
  future.push(current);
110
122
  isTimeTraveling = true;
111
123
  try {
112
- baseSetState(previous);
124
+ baseSetState((draft) => {
125
+ applySnapshot(
126
+ draft,
127
+ previous,
128
+ current
129
+ );
130
+ });
113
131
  } finally {
114
132
  isTimeTraveling = false;
115
133
  }
@@ -124,7 +142,13 @@ var history = ({
124
142
  past.push(current);
125
143
  isTimeTraveling = true;
126
144
  try {
127
- baseSetState(next);
145
+ baseSetState((draft) => {
146
+ applySnapshot(
147
+ draft,
148
+ next,
149
+ current
150
+ );
151
+ });
128
152
  } finally {
129
153
  isTimeTraveling = false;
130
154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coaction/history",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "A undo/redo middleware for Coaction",
5
5
  "keywords": [
6
6
  "state",
@@ -40,7 +40,7 @@
40
40
  "url": "https://github.com/unadlib/coaction/issues"
41
41
  },
42
42
  "peerDependencies": {
43
- "coaction": "^1.2.0"
43
+ "coaction": "^1.4.0"
44
44
  },
45
45
  "peerDependenciesMeta": {
46
46
  "coaction": {
@@ -48,7 +48,7 @@
48
48
  }
49
49
  },
50
50
  "devDependencies": {
51
- "coaction": "1.2.0"
51
+ "coaction": "1.4.0"
52
52
  },
53
53
  "publishConfig": {
54
54
  "access": "public",