mobx-react-use-autorun 3.0.24 → 3.0.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/README.md
CHANGED
|
@@ -72,17 +72,17 @@ Form validation<br/>
|
|
|
72
72
|
</div>)
|
|
73
73
|
})
|
|
74
74
|
|
|
75
|
-
useMobxState
|
|
75
|
+
useMobxState provides two usages.<br/>
|
|
76
|
+
|
|
77
|
+
useMobxState({},{}) is easy to use, you can define state and third-party hooks.<br/>
|
|
76
78
|
|
|
77
|
-
useMobxState({},{})使用简单, 可以定义state和第三方hooks.
|
|
78
79
|
|
|
79
80
|
useMobxState(()=>({
|
|
80
81
|
get (){
|
|
81
82
|
return state.name
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
})) 提供高级用法, state只执行一次, 性能更好, 同时可以使用get计算属性, 在计算值变化时, 重新计算.
|
|
83
|
+
},
|
|
84
|
+
name,
|
|
85
|
+
}),{}) provides advanced usage, the state is executed only once, and the performance is better. At the same time, you can use the get computed property to recalculate when the computed value changes.<br/>
|
|
86
86
|
|
|
87
87
|
## Notes - Subscription property changes with useMobxEffect
|
|
88
88
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useMobxState<T extends Record<any, any>, P extends Record<any, any>>(state: T | (() => T), props?: P
|
|
1
|
+
export declare function useMobxState<T extends Record<any, any>, P extends Record<any, any>>(state: T | (() => T), props?: P): T & P;
|
package/dist/lib/useMobxState.js
CHANGED
|
@@ -5,16 +5,15 @@ export function useMobxState(state, props) {
|
|
|
5
5
|
runInAction(function () {
|
|
6
6
|
var _a, _b;
|
|
7
7
|
var _c;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
Object.defineProperty(mobxState, key, Object.getOwnPropertyDescriptor(propsResult, key));
|
|
8
|
+
if (props) {
|
|
9
|
+
for (var key in props) {
|
|
10
|
+
if (isObservable(props[key]) || ((_c = Object.getOwnPropertyDescriptor(props, key)) === null || _c === void 0 ? void 0 : _c.get)) {
|
|
11
|
+
Object.defineProperty(mobxState, key, Object.getOwnPropertyDescriptor(props, key));
|
|
13
12
|
}
|
|
14
13
|
else {
|
|
15
|
-
if (
|
|
14
|
+
if (props[key] !== mobxState[key]) {
|
|
16
15
|
remove(mobxState, key);
|
|
17
|
-
extendObservable(mobxState, (_a = {}, _a[key] =
|
|
16
|
+
extendObservable(mobxState, (_a = {}, _a[key] = props[key], _a), (_b = {}, _b[key] = false, _b));
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
}
|
|
@@ -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,WAAW,EAAE,MAAM,MAAM,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,UAAU,YAAY,CAAyD,KAAoB,EAAE,
|
|
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,KAAS;IAChH,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;;;QAER,IAAI,KAAK,EAAE;YACP,KAAK,IAAM,GAAG,IAAI,KAAK,EAAE;gBACrB,IAAI,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAI,MAAA,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,GAAG,CAAC,0CAAE,GAAG,CAAA,EAAE;oBAC9E,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,GAAG,EAAE,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,GAAG,CAAQ,CAAC,CAAA;iBAC5F;qBAAM;oBACH,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,GAAG,CAAC,EAAE;wBAC/B,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;wBACvB,gBAAgB,CAAC,SAAS,YAAI,GAAC,GAAG,IAAG,KAAK,CAAC,GAAG,CAAC,iBAAM,GAAC,GAAG,IAAG,KAAK,MAAG,CAAA;qBACvE;iBACJ;aACJ;SACJ;IACL,CAAC,CAAC,CAAA;IAEF,OAAO,SAAgB,CAAC;AAC5B,CAAC"}
|
package/lib/lib/useMobxState.tsx
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
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 | (() => T), props?: P
|
|
4
|
+
export function useMobxState<T extends Record<any, any>, P extends Record<any, any>>(state: T | (() => T), props?: P): T & P {
|
|
5
5
|
const mobxState = useLocalObservable(typeof state === "function" ? (state as any) : () => state);
|
|
6
6
|
|
|
7
7
|
runInAction(() => {
|
|
8
|
-
const propsResult = typeof props === "function" ? (props as any)() : props;
|
|
9
8
|
|
|
10
|
-
if (
|
|
11
|
-
for (const key in
|
|
12
|
-
if (isObservable(
|
|
13
|
-
Object.defineProperty(mobxState, key, Object.getOwnPropertyDescriptor(
|
|
9
|
+
if (props) {
|
|
10
|
+
for (const key in props) {
|
|
11
|
+
if (isObservable(props[key]) || Object.getOwnPropertyDescriptor(props, key)?.get) {
|
|
12
|
+
Object.defineProperty(mobxState, key, Object.getOwnPropertyDescriptor(props, key) as any)
|
|
14
13
|
} else {
|
|
15
|
-
if (
|
|
14
|
+
if (props[key] !== mobxState[key]) {
|
|
16
15
|
remove(mobxState, key);
|
|
17
|
-
extendObservable(mobxState, { [key]:
|
|
16
|
+
extendObservable(mobxState, { [key]: props[key] }, { [key]: false })
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"mobx-react-use-autorun","version":"3.0.
|
|
1
|
+
{"name":"mobx-react-use-autorun","version":"3.0.26","description":"React Hook for mobx","scripts":{"test":"npx -y -p typescript -p ts-node ts-node --skipProject bin/mobx_react_test.ts","build":"npx -y -p typescript -p ts-node ts-node --skipProject bin/mobx_react_build.ts","make":"npx -y -p typescript -p ts-node ts-node --skipProject bin/mobx_react_make.ts"},"dependencies":{"mobx":">=6.5.0","mobx-react-lite":">=3.3.0","react-use":">=17.3.2","rxjs":">=6.0.0"},"peerDependencies":{"react":">=16.8.0"},"license":"MIT","keywords":["react","mobx","typescript"],"main":"./dist/index.js","types":"./dist/index.d.ts","eslintConfig":{"extends":["react-app","react-app/jest"]},"homepage":"https://github.com/zdu-strong/mobx-react-use-autorun#readme","repository":{"type":"git","url":"git+https://github.com/zdu-strong/mobx-react-use-autorun.git"},"files":["lib","dist"],"bugs":{"url":"https://github.com/zdu-strong/mobx-react-use-autorun/issues"},"publishConfig":{"registry":"https://registry.npmjs.org/"}}
|