@ztimson/utils 0.26.25 → 0.26.26

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.mjs CHANGED
@@ -122,10 +122,11 @@ function applyDeltas(target, deltas) {
122
122
  for (const [key, value] of Object.entries(delta)) {
123
123
  if (value === null) {
124
124
  delete target[key];
125
- } else if (typeof value === "object" && !Array.isArray(value)) {
126
- if (typeof target[key] !== "object" || Array.isArray(target[key])) {
125
+ } else if (Array.isArray(value)) {
126
+ target[key] = [...value];
127
+ } else if (typeof value === "object") {
128
+ if (typeof target[key] !== "object" || Array.isArray(target[key]) || !target[key])
127
129
  target[key] = {};
128
- }
129
130
  applyDeltas(target[key], [value]);
130
131
  } else {
131
132
  target[key] = value;
@@ -144,7 +145,9 @@ function calcDelta(old, target) {
144
145
  delta[key] = val1;
145
146
  } else if (!(key in old)) {
146
147
  delta[key] = null;
147
- } else if (typeof val1 === "object" && typeof val2 === "object" && val1 && val2 && !Array.isArray(val1)) {
148
+ } else if (Array.isArray(val1) || Array.isArray(val2)) {
149
+ if (JSON.stringify(val1) !== JSON.stringify(val2)) delta[key] = val1;
150
+ } else if (typeof val1 === "object" && typeof val2 === "object" && val1 && val2) {
148
151
  const nested = calcDelta(val1, val2);
149
152
  if (Object.keys(nested).length) delta[key] = nested;
150
153
  } else if (val1 !== val2) {