mobx-react-use-autorun 1.0.21 → 1.0.24
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,8 +1,7 @@
|
|
|
1
1
|
import './mobx_config';
|
|
2
|
-
import { observable,
|
|
2
|
+
import { observable, runInAction } from 'mobx';
|
|
3
3
|
import { useRef } from 'react';
|
|
4
4
|
export function useAsLocalSource(data) {
|
|
5
|
-
var _a, _b;
|
|
6
5
|
var initStateCallback = function () {
|
|
7
6
|
if (Array.isArray(data)) {
|
|
8
7
|
throw new Error('Arrays is unsupported!');
|
|
@@ -11,23 +10,33 @@ export function useAsLocalSource(data) {
|
|
|
11
10
|
return initState;
|
|
12
11
|
};
|
|
13
12
|
var state = useRef(initStateCallback());
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (
|
|
13
|
+
runInAction(function () {
|
|
14
|
+
for (var key in state.current) {
|
|
15
|
+
if (!Object.keys(data).includes(key)) {
|
|
17
16
|
delete state.current[key];
|
|
18
|
-
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
var _loop_1 = function (key) {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
if (typeof data[key] === 'function') {
|
|
22
|
+
Object.assign(state.current, (_a = {},
|
|
23
|
+
Object.defineProperty(_a, key, {
|
|
24
|
+
get: function () {
|
|
25
|
+
return data[key];
|
|
26
|
+
},
|
|
27
|
+
enumerable: false,
|
|
28
|
+
configurable: true
|
|
29
|
+
}),
|
|
30
|
+
_a));
|
|
19
31
|
}
|
|
20
32
|
else {
|
|
21
|
-
|
|
22
|
-
delete state.current[key];
|
|
23
|
-
extendObservable(state.current, (_b = {}, _b[key] = data[key], _b));
|
|
24
|
-
}
|
|
33
|
+
Object.assign(state.current, (_b = {}, _b[key] = data[key], _b));
|
|
25
34
|
}
|
|
35
|
+
};
|
|
36
|
+
for (var key in data) {
|
|
37
|
+
_loop_1(key);
|
|
26
38
|
}
|
|
27
|
-
|
|
28
|
-
state.current[key] = data[key];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
39
|
+
});
|
|
31
40
|
return state.current;
|
|
32
41
|
}
|
|
33
42
|
;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAsLocalSource.js","sourceRoot":"","sources":["../../lib/lib/useAsLocalSource.tsx"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AACtB,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"useAsLocalSource.js","sourceRoot":"","sources":["../../lib/lib/useAsLocalSource.tsx"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AACtB,OAAO,EAAE,UAAU,EAAoB,WAAW,EAAE,MAAM,MAAM,CAAC;AACjE,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,WAAW,CAAC;QACR,KAAK,IAAM,GAAG,IAAI,KAAK,CAAC,OAAO,EAAE;YAC7B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;gBAClC,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;aAC7B;SACJ;gCACU,GAAG;;YACV,IAAI,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,UAAU,EAAE;gBACjC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO;0CACnB,OAAK;6BAAT;4BACI,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;wBACrB,CAAC;;;;wBACH,CAAA;aACL;iBAAM;gBACH,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,YAAI,GAAC,GAAG,IAAG,IAAI,CAAC,GAAG,CAAC,MAAG,CAAA;aACrD;;QATL,KAAK,IAAM,GAAG,IAAI,IAAI;oBAAX,GAAG;SAUb;IACL,CAAC,CAAC,CAAA;IAEF,OAAO,KAAK,CAAC,OAAO,CAAC;AACzB,CAAC;AAAA,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import './mobx_config'
|
|
2
|
-
import { observable, extendObservable } from 'mobx';
|
|
2
|
+
import { observable, extendObservable, runInAction } from 'mobx';
|
|
3
3
|
import { useRef } from 'react';
|
|
4
4
|
|
|
5
5
|
export function useAsLocalSource<T extends object>(data: T): T {
|
|
@@ -14,21 +14,24 @@ export function useAsLocalSource<T extends object>(data: T): T {
|
|
|
14
14
|
|
|
15
15
|
const state = useRef(initStateCallback());
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (
|
|
17
|
+
runInAction(() => {
|
|
18
|
+
for (const key in state.current) {
|
|
19
|
+
if (!Object.keys(data).includes(key)) {
|
|
20
20
|
delete state.current[key];
|
|
21
|
-
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
for (const key in data) {
|
|
24
|
+
if (typeof data[key] === 'function') {
|
|
25
|
+
Object.assign(state.current, {
|
|
26
|
+
get [key]() {
|
|
27
|
+
return data[key];
|
|
28
|
+
}
|
|
29
|
+
})
|
|
22
30
|
} else {
|
|
23
|
-
|
|
24
|
-
delete state.current[key];
|
|
25
|
-
extendObservable(state.current, { [key]: data[key] })
|
|
26
|
-
}
|
|
31
|
+
Object.assign(state.current, { [key]: data[key] })
|
|
27
32
|
}
|
|
28
|
-
} else {
|
|
29
|
-
state.current[key] = data[key];
|
|
30
33
|
}
|
|
31
|
-
}
|
|
34
|
+
})
|
|
32
35
|
|
|
33
36
|
return state.current;
|
|
34
37
|
};
|
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.24",
|
|
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",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@babel/preset-typescript": "7.16.7",
|
|
24
24
|
"@testing-library/react-hooks": "8.0.0",
|
|
25
25
|
"@types/jest": "27.5.0",
|
|
26
|
-
"@types/node": "
|
|
26
|
+
"@types/node": "17.0.31",
|
|
27
27
|
"@types/react": "17.0.44",
|
|
28
28
|
"babel-jest": "28.0.3",
|
|
29
29
|
"jest": "28.0.3",
|
|
@@ -31,8 +31,7 @@
|
|
|
31
31
|
"react": "17.0.2",
|
|
32
32
|
"react-dom": "17.0.2",
|
|
33
33
|
"ts-node": "10.7.0",
|
|
34
|
-
"typescript": "
|
|
35
|
-
"wait-on": "6.0.1"
|
|
34
|
+
"typescript": "4.6.4"
|
|
36
35
|
},
|
|
37
36
|
"license": "MIT",
|
|
38
37
|
"main": "./dist/index.js",
|