mobx-react-hook-form 5.1.2 → 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;CAoD5B"}
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, toJS } from 'mobx';
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 currentData = toJS(this.data);
17
- const stack = Object.keys(currentData).map((it) => ({
18
- key: it,
19
- currObservable: this.data,
20
- curr: currentData,
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 item = stack.shift();
25
- const newValue = item.new[item.key];
26
- const currValue = item.curr[item.key];
27
- if (item.key in item.new) {
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((key) => {
31
- if (!(key in newValue)) {
32
- delete item.currObservable[item.key][key];
28
+ Object.keys(currValue).forEach((childKey) => {
29
+ if (!(childKey in newValue)) {
30
+ delete currObservableData[key][childKey];
33
31
  }
34
32
  });
35
- newValueKeys.forEach((key) => {
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
- item.currObservable[item.key] = newValue;
38
+ currObservableData[key] = newValue;
46
39
  }
47
40
  }
48
41
  else {
49
- delete item.currObservable[item.key];
42
+ delete currObservableData[key];
50
43
  }
51
44
  }
52
45
  Object.keys(newData).forEach((newDataKey) => {
53
- if (!currentData[newDataKey]) {
46
+ if (!this.data[newDataKey]) {
54
47
  // @ts-ignore
55
48
  this.data[newDataKey] = newData[newDataKey];
56
49
  }
@@ -388,11 +388,11 @@ export class Form {
388
388
  */
389
389
  submit(e) {
390
390
  return new Promise((resolve, reject) => {
391
- this.originalForm.handleSubmit((data, event) => {
392
- this.config.onSubmit?.(data, event);
391
+ this.originalForm.handleSubmit(async (data, event) => {
392
+ await this.config.onSubmit?.(data, event);
393
393
  resolve(data);
394
- }, (errors, event) => {
395
- this.config.onSubmitFailed?.(errors, event);
394
+ }, async (errors, event) => {
395
+ await this.config.onSubmitFailed?.(errors, event);
396
396
  reject(errors);
397
397
  })(e);
398
398
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobx-react-hook-form",
3
- "version": "5.1.2",
3
+ "version": "5.1.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "keywords": [],