mobx-react-hook-form 1.0.1 → 1.0.2
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/mobx-form/mobx-form.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Disposable, IDisposer } from 'disposer-util';
|
|
2
|
-
import { FormState, UseFormProps, UseFormReturn } from 'react-hook-form';
|
|
2
|
+
import { DeepPartial, FormState, UseFormProps, UseFormReturn } from 'react-hook-form';
|
|
3
3
|
import { AnyObject, Maybe } from 'yammies/utils/types';
|
|
4
4
|
import { ConnectedMobxForm, MobxFormParams } from './mobx-form.types';
|
|
5
5
|
export declare class MobxForm<TFieldValues extends AnyObject, TContext = any> implements Disposable {
|
|
@@ -10,7 +10,8 @@ export declare class MobxForm<TFieldValues extends AnyObject, TContext = any> im
|
|
|
10
10
|
protected resetHandler?: MobxFormParams<TFieldValues, TContext>['onReset'];
|
|
11
11
|
form: Maybe<UseFormReturn<TFieldValues, TContext>>;
|
|
12
12
|
state: FormState<TFieldValues>;
|
|
13
|
-
data: Maybe<TFieldValues
|
|
13
|
+
data: Maybe<DeepPartial<TFieldValues>>;
|
|
14
|
+
protected isConnected: boolean;
|
|
14
15
|
constructor({ disposer, onSubmit, onSubmitFailed, onReset, ...RHFParams }: MobxFormParams<TFieldValues, TContext>);
|
|
15
16
|
getRHFParams(): Partial<{
|
|
16
17
|
mode: import("react-hook-form").Mode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mobx-form.d.ts","sourceRoot":"","sources":["../../src/mobx-form/mobx-form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAY,SAAS,EAAE,MAAM,eAAe,CAAC;AAGhE,OAAO,
|
|
1
|
+
{"version":3,"file":"mobx-form.d.ts","sourceRoot":"","sources":["../../src/mobx-form/mobx-form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAY,SAAS,EAAE,MAAM,eAA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O,IAAI,IAAI;CAMhB"}
|
package/mobx-form/mobx-form.js
CHANGED
|
@@ -10,6 +10,7 @@ export class MobxForm {
|
|
|
10
10
|
form;
|
|
11
11
|
state;
|
|
12
12
|
data;
|
|
13
|
+
isConnected = false;
|
|
13
14
|
constructor({ disposer, onSubmit, onSubmitFailed, onReset, ...RHFParams }) {
|
|
14
15
|
this.disposer = disposer ?? new Disposer();
|
|
15
16
|
this.state = {
|
|
@@ -41,11 +42,21 @@ export class MobxForm {
|
|
|
41
42
|
return this.RHFParams;
|
|
42
43
|
}
|
|
43
44
|
connectRHF(formResult) {
|
|
44
|
-
|
|
45
|
-
this.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
if (!this.isConnected) {
|
|
46
|
+
this.isConnected = true;
|
|
47
|
+
runInAction(() => {
|
|
48
|
+
this.form = formResult;
|
|
49
|
+
this.state = formResult.formState;
|
|
50
|
+
this.data = formResult.getValues();
|
|
51
|
+
});
|
|
52
|
+
this.disposer.add(formResult.watch(() => {
|
|
53
|
+
runInAction(() => {
|
|
54
|
+
this.form = formResult;
|
|
55
|
+
this.state = formResult.formState;
|
|
56
|
+
this.data = formResult.getValues();
|
|
57
|
+
});
|
|
58
|
+
}).unsubscribe);
|
|
59
|
+
}
|
|
49
60
|
return {
|
|
50
61
|
...formResult,
|
|
51
62
|
onReset: this.resetHandler ?? noop,
|