mobx-react-hook-form 5.1.3 → 5.1.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deep-observable-struct.d.ts","sourceRoot":"","sources":["../../src/mobx-form/deep-observable-struct.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,qBAAa,oBAAoB,CAAC,KAAK,SAAS,SAAS;IACvD,IAAI,EAAE,KAAK,CAAC;gBAEA,IAAI,EAAE,KAAK;IASvB,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"deep-observable-struct.d.ts","sourceRoot":"","sources":["../../src/mobx-form/deep-observable-struct.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,qBAAa,oBAAoB,CAAC,KAAK,SAAS,SAAS;IACvD,IAAI,EAAE,KAAK,CAAC;gBAEA,IAAI,EAAE,KAAK;IASvB,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC;CA0C5B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
2
|
/* eslint-disable no-prototype-builtins */
|
|
3
3
|
/* eslint-disable sonarjs/cognitive-complexity */
|
|
4
|
-
import { action, makeObservable, observable
|
|
4
|
+
import { action, makeObservable, observable } from 'mobx';
|
|
5
5
|
import { typeGuard } from 'yummies/type-guard';
|
|
6
6
|
export class DeepObservableStruct {
|
|
7
7
|
data;
|
|
@@ -13,44 +13,37 @@ export class DeepObservableStruct {
|
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
set(newData) {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
new: newData,
|
|
22
|
-
}));
|
|
16
|
+
const stack = Object.keys(this.data).map((key) => [
|
|
17
|
+
key,
|
|
18
|
+
this.data,
|
|
19
|
+
newData,
|
|
20
|
+
]);
|
|
23
21
|
while (stack.length > 0) {
|
|
24
|
-
const
|
|
25
|
-
const newValue =
|
|
26
|
-
const currValue =
|
|
27
|
-
if (
|
|
22
|
+
const [key, currObservableData, newData] = stack.shift();
|
|
23
|
+
const newValue = newData[key];
|
|
24
|
+
const currValue = currObservableData[key];
|
|
25
|
+
if (key in newData) {
|
|
28
26
|
if (typeGuard.isObject(newValue) && typeGuard.isObject(currValue)) {
|
|
29
27
|
const newValueKeys = Object.keys(newValue);
|
|
30
|
-
Object.keys(currValue).forEach((
|
|
31
|
-
if (!(
|
|
32
|
-
delete
|
|
28
|
+
Object.keys(currValue).forEach((childKey) => {
|
|
29
|
+
if (!(childKey in newValue)) {
|
|
30
|
+
delete currObservableData[key][childKey];
|
|
33
31
|
}
|
|
34
32
|
});
|
|
35
|
-
newValueKeys.forEach((
|
|
36
|
-
stack.push(
|
|
37
|
-
key,
|
|
38
|
-
currObservable: item.currObservable[item.key],
|
|
39
|
-
curr: currValue,
|
|
40
|
-
new: newValue,
|
|
41
|
-
});
|
|
33
|
+
newValueKeys.forEach((childKey) => {
|
|
34
|
+
stack.push([childKey, currObservableData[key], newValue]);
|
|
42
35
|
});
|
|
43
36
|
}
|
|
44
37
|
else if (newValue !== currValue) {
|
|
45
|
-
|
|
38
|
+
currObservableData[key] = newValue;
|
|
46
39
|
}
|
|
47
40
|
}
|
|
48
41
|
else {
|
|
49
|
-
delete
|
|
42
|
+
delete currObservableData[key];
|
|
50
43
|
}
|
|
51
44
|
}
|
|
52
45
|
Object.keys(newData).forEach((newDataKey) => {
|
|
53
|
-
if (!
|
|
46
|
+
if (!this.data[newDataKey]) {
|
|
54
47
|
// @ts-ignore
|
|
55
48
|
this.data[newDataKey] = newData[newDataKey];
|
|
56
49
|
}
|