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
- }),(props: {name: string})=>({
85
- ...props
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, Please do not execute toJS(state) in component rendering code, it may cause repeated rendering. Wrong Usage Demonstration:
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 | (() => P)): T & P;
1
+ export declare function useMobxState<T extends Record<any, any>, P extends Record<any, any>>(state: T | (() => T), props?: P): T & P;
@@ -5,16 +5,15 @@ export function useMobxState(state, props) {
5
5
  runInAction(function () {
6
6
  var _a, _b;
7
7
  var _c;
8
- var propsResult = typeof props === "function" ? props() : props;
9
- if (propsResult) {
10
- for (var key in propsResult) {
11
- if (isObservable(propsResult[key]) || ((_c = Object.getOwnPropertyDescriptor(propsResult, key)) === null || _c === void 0 ? void 0 : _c.get)) {
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 (propsResult[key] !== mobxState[key]) {
14
+ if (props[key] !== mobxState[key]) {
16
15
  remove(mobxState, key);
17
- extendObservable(mobxState, (_a = {}, _a[key] = propsResult[key], _a), (_b = {}, _b[key] = false, _b));
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,KAAqB;IAC5H,IAAM,SAAS,GAAG,kBAAkB,CAAC,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAE,KAAa,CAAC,CAAC,CAAC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AA,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"}
@@ -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 | (() => P)): T & 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 (propsResult) {
11
- for (const key in propsResult) {
12
- if (isObservable(propsResult[key]) || Object.getOwnPropertyDescriptor(propsResult, key)?.get) {
13
- Object.defineProperty(mobxState, key, Object.getOwnPropertyDescriptor(propsResult, key) as any)
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 (propsResult[key] !== mobxState[key]) {
14
+ if (props[key] !== mobxState[key]) {
16
15
  remove(mobxState, key);
17
- extendObservable(mobxState, { [key]: propsResult[key] }, { [key]: false })
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.25","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/"}}
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/"}}