mobx-react-use-autorun 3.0.25 → 3.0.27
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
|
@@ -80,10 +80,9 @@ useMobxState({},{}) is easy to use, you can define state and third-party hooks.<
|
|
|
80
80
|
useMobxState(()=>({
|
|
81
81
|
get (){
|
|
82
82
|
return state.name
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
})) 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/>
|
|
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/>
|
|
87
86
|
|
|
88
87
|
## Notes - Subscription property changes with useMobxEffect
|
|
89
88
|
|
|
@@ -104,7 +103,7 @@ useMobxState(()=>({
|
|
|
104
103
|
|
|
105
104
|
## Notes - Get the real data of the proxy object with toJS
|
|
106
105
|
|
|
107
|
-
toJS will cause data to be used,
|
|
106
|
+
toJS will cause data to be used, please do not execute toJS(state) in component rendering code, it may cause repeated rendering. Wrong Usage Demonstration:<br/>
|
|
108
107
|
|
|
109
108
|
import { toJS, observer, useMobxState } from 'mobx-react-use-autorun'
|
|
110
109
|
import { v1 } from 'uuid'
|
|
@@ -120,7 +119,7 @@ toJS will cause data to be used, Please do not execute toJS(state) in component
|
|
|
120
119
|
return null;
|
|
121
120
|
})
|
|
122
121
|
|
|
123
|
-
Other than that, all usages are correct. Example
|
|
122
|
+
Other than that, all usages are correct. Example:<br/>
|
|
124
123
|
|
|
125
124
|
import { toJS, useMobxEffect, observer, useMobxState } from 'mobx-react-use-autorun';
|
|
126
125
|
import { v1 } from 'uuid'
|
|
@@ -148,8 +147,8 @@ Other than that, all usages are correct. Example:
|
|
|
148
147
|
|
|
149
148
|
## Introduction to third-party hooks
|
|
150
149
|
|
|
151
|
-
useMount is executed when the component loaded
|
|
152
|
-
useUnmount is executed when the component is unmount
|
|
150
|
+
useMount is executed when the component loaded.<br/>
|
|
151
|
+
useUnmount is executed when the component is unmount.<br/>
|
|
153
152
|
|
|
154
153
|
import { useMount, useUnmount } from 'react-use'
|
|
155
154
|
import { Subscription, of, tap } from 'rxjs'
|
|
@@ -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,MA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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.27","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/"}}
|