mobx-react-use-autorun 3.0.3 → 3.0.7
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,6 +1 @@
|
|
|
1
|
-
export declare function useMobxState<T extends Record<any, any>, P extends Record<any, any>>(state: T, props
|
|
2
|
-
export declare function useMobxState<T extends Record<any, any>, P extends Record<any, any>>(statefn: () => T, propsfn: () => P): T & P;
|
|
3
|
-
export declare function useMobxState<T extends Record<any, any>, P extends Record<any, any>>(state: T, propsfn: () => P): T & P;
|
|
4
|
-
export declare function useMobxState<T extends Record<any, any>, P extends Record<any, any>>(statefn: () => T, props: P): T & P;
|
|
5
|
-
export declare function useMobxState<T extends Record<any, any>>(state: T): T;
|
|
6
|
-
export declare function useMobxState<T extends Record<any, any>>(statefn: () => T): T;
|
|
1
|
+
export declare function useMobxState<T extends Record<any, any>, P extends Record<any, any>>(state: T | (() => T), props?: P | (() => P)): T & P;
|
package/dist/lib/useMobxState.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import { extendObservable, remove, isObservable } from 'mobx';
|
|
1
|
+
import { extendObservable, remove, isObservable, runInAction } from 'mobx';
|
|
2
2
|
import { useLocalObservable } from 'mobx-react-lite';
|
|
3
3
|
export function useMobxState(state, props) {
|
|
4
|
-
var _a, _b;
|
|
5
4
|
var mobxState = useLocalObservable(typeof state === "function" ? state : function () { return state; });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
runInAction(function () {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
var propsResult = typeof props === "function" ? props() : props;
|
|
8
|
+
if (propsResult) {
|
|
9
|
+
for (var key in propsResult) {
|
|
10
|
+
if (isObservable(propsResult[key])) {
|
|
11
|
+
mobxState[key] = propsResult[key];
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
if (propsResult[key] !== mobxState[key]) {
|
|
15
|
+
remove(mobxState, key);
|
|
16
|
+
extendObservable(mobxState, (_a = {}, _a[key] = propsResult[key], _a), (_b = {}, _b[key] = false, _b));
|
|
17
|
+
}
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
|
-
}
|
|
21
|
+
});
|
|
20
22
|
return mobxState;
|
|
21
23
|
}
|
|
22
24
|
//# sourceMappingURL=useMobxState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMobxState.js","sourceRoot":"","sources":["../../lib/lib/useMobxState.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"useMobxState.js","sourceRoot":"","sources":["../../lib/lib/useMobxState.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,UAAU,YAAY,CAAyD,KAAoB,EAAE,KAAqB;IAC5H,IAAM,SAAS,GAAG,kBAAkB,CAAC,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAE,KAAa,CAAC,CAAC,CAAC,cAAM,OAAA,KAAK,EAAL,CAAK,CAAC,CAAC;IAEjG,WAAW,CAAC;;QACR,IAAM,WAAW,GAAG,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAE,KAAa,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;QAE3E,IAAI,WAAW,EAAE;YACb,KAAK,IAAM,GAAG,IAAI,WAAW,EAAE;gBAC3B,IAAI,YAAY,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE;oBAChC,SAAS,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;iBACrC;qBAAM;oBACH,IAAI,WAAW,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,GAAG,CAAC,EAAE;wBACrC,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;wBACvB,gBAAgB,CAAC,SAAS,YAAI,GAAC,GAAG,IAAG,WAAW,CAAC,GAAG,CAAC,iBAAM,GAAC,GAAG,IAAG,KAAK,MAAG,CAAA;qBAC7E;iBACJ;aACJ;SACJ;IACL,CAAC,CAAC,CAAA;IAEF,OAAO,SAAgB,CAAC;AAC5B,CAAC"}
|
package/lib/lib/useMobxState.tsx
CHANGED
|
@@ -1,31 +1,25 @@
|
|
|
1
|
-
import { extendObservable, remove, isObservable } from 'mobx';
|
|
1
|
+
import { extendObservable, remove, isObservable, runInAction } from 'mobx';
|
|
2
2
|
import { useLocalObservable } from 'mobx-react-lite';
|
|
3
3
|
|
|
4
|
-
export function useMobxState<T extends Record<any, any>, P extends Record<any, any>>(state: T, props
|
|
5
|
-
export function useMobxState<T extends Record<any, any>, P extends Record<any, any>>(statefn: () => T, propsfn: () => P): T & P;
|
|
6
|
-
export function useMobxState<T extends Record<any, any>, P extends Record<any, any>>(state: T, propsfn: () => P): T & P;
|
|
7
|
-
export function useMobxState<T extends Record<any, any>, P extends Record<any, any>>(statefn: () => T, props: P): T & P;
|
|
8
|
-
export function useMobxState<T extends Record<any, any>>(state: T): T;
|
|
9
|
-
export function useMobxState<T extends Record<any, any>>(statefn: () => T): T;
|
|
10
|
-
|
|
11
|
-
export function useMobxState(state: any, props?: any): any {
|
|
12
|
-
|
|
4
|
+
export function useMobxState<T extends Record<any, any>, P extends Record<any, any>>(state: T | (() => T), props?: P | (() => P)): T & P {
|
|
13
5
|
const mobxState = useLocalObservable(typeof state === "function" ? (state as any) : () => state);
|
|
14
6
|
|
|
15
|
-
|
|
7
|
+
runInAction(() => {
|
|
8
|
+
const propsResult = typeof props === "function" ? (props as any)() : props;
|
|
16
9
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
if (propsResult) {
|
|
11
|
+
for (const key in propsResult) {
|
|
12
|
+
if (isObservable(propsResult[key])) {
|
|
13
|
+
mobxState[key] = propsResult[key];
|
|
14
|
+
} else {
|
|
15
|
+
if (propsResult[key] !== mobxState[key]) {
|
|
16
|
+
remove(mobxState, key);
|
|
17
|
+
extendObservable(mobxState, { [key]: propsResult[key] }, { [key]: false })
|
|
18
|
+
}
|
|
25
19
|
}
|
|
26
20
|
}
|
|
27
21
|
}
|
|
28
|
-
}
|
|
22
|
+
})
|
|
29
23
|
|
|
30
24
|
return mobxState as any;
|
|
31
25
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx-react-use-autorun",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7",
|
|
4
4
|
"description": "React Hook for mobx",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "npm install -g typescript@4.6.3 @types/node@17.0.23 ts-node@10.7.0 cross-env@7.0.3 && cross-env TS_NODE_SKIP_PROJECT=true ts-node bin/mobx_react_build.ts",
|