mobx-react-use-autorun 1.0.13 → 1.0.16
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
|
@@ -105,6 +105,36 @@ Form validation<br/>
|
|
|
105
105
|
</div>
|
|
106
106
|
})
|
|
107
107
|
|
|
108
|
+
## Notes - Ignore frequent asynchronous calls with useAsyncExhaust
|
|
109
|
+
|
|
110
|
+
import { TextField } from "@mui/material";
|
|
111
|
+
import { useLocalObservable, observer, useAsyncExhaust } from 'mobx-react-use-autorun';
|
|
112
|
+
import axios from 'axios';
|
|
113
|
+
|
|
114
|
+
export default observer(() => {
|
|
115
|
+
|
|
116
|
+
const state = useLocalObservable(() => ({
|
|
117
|
+
list: [],
|
|
118
|
+
searchText: ""
|
|
119
|
+
}));
|
|
120
|
+
|
|
121
|
+
const search = useAsyncExhaust(async () => {
|
|
122
|
+
state.list = await axios.get("/search");
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<TextField
|
|
127
|
+
label="Please enter search content"
|
|
128
|
+
variant="outlined"
|
|
129
|
+
value={state.searchText}
|
|
130
|
+
onChange={(e) => {
|
|
131
|
+
state.searchText = e.target.value;
|
|
132
|
+
search();
|
|
133
|
+
}}
|
|
134
|
+
/>
|
|
135
|
+
);
|
|
136
|
+
})
|
|
137
|
+
|
|
108
138
|
## Notes - Define global mutable data
|
|
109
139
|
|
|
110
140
|
import { observable } from 'mobx-react-use-autorun';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import './mobx_config';
|
|
2
|
-
import { observable } from 'mobx';
|
|
2
|
+
import { observable, extendObservable } from 'mobx';
|
|
3
3
|
import { useRef } from 'react';
|
|
4
4
|
export function useAsLocalSource(data) {
|
|
5
|
+
var _a;
|
|
5
6
|
var initStateCallback = function () {
|
|
6
7
|
if (Array.isArray(data)) {
|
|
7
8
|
throw new Error('Arrays is unsupported!');
|
|
@@ -12,8 +13,9 @@ export function useAsLocalSource(data) {
|
|
|
12
13
|
var state = useRef(initStateCallback());
|
|
13
14
|
for (var key in data) {
|
|
14
15
|
if (typeof data[key] === 'function') {
|
|
15
|
-
if (
|
|
16
|
-
state.current[key]
|
|
16
|
+
if (data[key] !== state.current[key]) {
|
|
17
|
+
delete state.current[key];
|
|
18
|
+
extendObservable(state.current, (_a = {}, _a[key] = data[key], _a));
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAsLocalSource.js","sourceRoot":"","sources":["../../lib/lib/useAsLocalSource.tsx"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"useAsLocalSource.js","sourceRoot":"","sources":["../../lib/lib/useAsLocalSource.tsx"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AACtB,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,MAAM,UAAU,gBAAgB,CAAmB,IAAO;;IAEtD,IAAM,iBAAiB,GAAG;QACtB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACrB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;SAC7C;QACD,IAAM,SAAS,GAAG,UAAU,CAAC,EAAE,CAAM,CAAC;QACtC,OAAO,SAAS,CAAC;IACrB,CAAC,CAAC;IAEF,IAAM,KAAK,GAAG,MAAM,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAE1C,KAAK,IAAM,GAAG,IAAI,IAAI,EAAE;QACpB,IAAI,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,UAAU,EAAE;YACjC,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;gBAClC,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBAC1B,gBAAgB,CAAC,KAAK,CAAC,OAAO,YAAI,GAAC,GAAG,IAAG,IAAI,CAAC,GAAG,CAAC,MAAG,CAAA;aACxD;SACJ;aAAM;YACH,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;SAClC;KACJ;IAED,OAAO,KAAK,CAAC,OAAO,CAAC;AACzB,CAAC;AAAA,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import './mobx_config'
|
|
2
|
-
import { observable } from 'mobx';
|
|
2
|
+
import { observable, extendObservable } from 'mobx';
|
|
3
3
|
import { useRef } from 'react';
|
|
4
4
|
|
|
5
5
|
export function useAsLocalSource<T extends object>(data: T): T {
|
|
@@ -16,8 +16,9 @@ export function useAsLocalSource<T extends object>(data: T): T {
|
|
|
16
16
|
|
|
17
17
|
for (const key in data) {
|
|
18
18
|
if (typeof data[key] === 'function') {
|
|
19
|
-
if(
|
|
20
|
-
state.current[key]
|
|
19
|
+
if (data[key] !== state.current[key]) {
|
|
20
|
+
delete state.current[key];
|
|
21
|
+
extendObservable(state.current, { [key]: data[key] })
|
|
21
22
|
}
|
|
22
23
|
} else {
|
|
23
24
|
state.current[key] = data[key];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx-react-use-autorun",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
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",
|