mobx-react-use-autorun 1.0.7 → 1.0.10
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 +3 -9
- package/dist/index.d.ts +12 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/mobx_config.d.ts +1 -0
- package/dist/lib/mobx_config.js +5 -0
- package/dist/lib/mobx_config.js.map +1 -0
- package/dist/lib/timeout.d.ts +1 -0
- package/dist/lib/timeout.js +50 -0
- package/dist/lib/timeout.js.map +1 -0
- package/dist/lib/useAsLocalSource.d.ts +2 -0
- package/dist/lib/useAsLocalSource.js +19 -0
- package/dist/lib/useAsLocalSource.js.map +1 -0
- package/dist/lib/useAsyncExhaust.d.ts +2 -0
- package/dist/lib/useAsyncExhaust.js +139 -0
- package/dist/lib/useAsyncExhaust.js.map +1 -0
- package/dist/lib/useAutorun.d.ts +2 -0
- package/dist/lib/useAutorun.js +27 -0
- package/dist/lib/useAutorun.js.map +1 -0
- package/{src → lib}/index.tsx +0 -0
- package/{src → lib}/lib/mobx_config.tsx +0 -0
- package/{src → lib}/lib/timeout.tsx +0 -0
- package/{src → lib}/lib/useAsLocalSource.tsx +0 -0
- package/{src → lib}/lib/useAsyncExhaust.tsx +0 -0
- package/{src → lib}/lib/useAutorun.tsx +0 -0
- package/package.json +12 -2
- package/.vscode/settings.json +0 -13
- package/babel.config.js +0 -6
- package/bin/mobx_react_build.ts +0 -29
- package/bin/mobx_react_test.ts +0 -27
- package/bin/pre_load_configuration.ts +0 -30
- package/jest.config.ts +0 -195
- package/test/timeout.test.tsx +0 -12
- package/test/use-as-local-source.test.tsx +0 -9
- package/test/use-async-exhaust.test.tsx +0 -18
- package/test/use-autorun.test.tsx +0 -17
- package/tsconfig.json +0 -29
package/README.md
CHANGED
|
@@ -13,19 +13,13 @@ In the project directory, you can run:<br/>
|
|
|
13
13
|
### `npm test`
|
|
14
14
|
|
|
15
15
|
Run all unit tests.<br/>
|
|
16
|
-
See the section about [running tests](https://www.cypress.io) for more information.<br/>
|
|
17
16
|
|
|
18
|
-
### `npm run build`
|
|
19
|
-
|
|
20
|
-
Builds the app for production to the `build` folder.<br/>
|
|
21
|
-
It correctly bundles React in production mode and optimizes the build for the best performance.<br/>
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
Your app is ready to be deployed!<br/>
|
|
18
|
+
### `npm run build`
|
|
25
19
|
|
|
26
|
-
|
|
20
|
+
Builds the files for production to the `dist` folder.<br/>
|
|
27
21
|
|
|
28
|
-
### `npm
|
|
22
|
+
### `npm publish`
|
|
29
23
|
|
|
30
24
|
Publish to npm repository
|
|
31
25
|
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import './lib/mobx_config';
|
|
2
|
+
import { toJS, observable } from 'mobx';
|
|
3
|
+
import { useLocalObservable, observer } from 'mobx-react-lite';
|
|
4
|
+
import { timeout } from './lib/timeout';
|
|
5
|
+
import { useAsLocalSource } from './lib/useAsLocalSource';
|
|
6
|
+
import { useAutorun } from './lib/useAutorun';
|
|
7
|
+
import { useAsyncExhaust } from './lib/useAsyncExhaust';
|
|
8
|
+
export { toJS, observable, observer, useLocalObservable };
|
|
9
|
+
export { timeout };
|
|
10
|
+
export { useAsLocalSource };
|
|
11
|
+
export { useAutorun };
|
|
12
|
+
export { useAsyncExhaust };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import './lib/mobx_config';
|
|
2
|
+
import { toJS, observable } from 'mobx';
|
|
3
|
+
import { useLocalObservable, observer } from 'mobx-react-lite';
|
|
4
|
+
import { timeout } from './lib/timeout';
|
|
5
|
+
import { useAsLocalSource } from './lib/useAsLocalSource';
|
|
6
|
+
import { useAutorun } from './lib/useAutorun';
|
|
7
|
+
import { useAsyncExhaust } from './lib/useAsyncExhaust';
|
|
8
|
+
export { toJS, observable, observer, useLocalObservable };
|
|
9
|
+
export { timeout };
|
|
10
|
+
export { useAsLocalSource };
|
|
11
|
+
export { useAutorun };
|
|
12
|
+
export { useAsyncExhaust };
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.tsx"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAA;AAC1B,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,kBAAkB,EAAE,CAAA;AACzD,OAAO,EAAE,OAAO,EAAE,CAAA;AAClB,OAAO,EAAE,gBAAgB,EAAE,CAAA;AAC3B,OAAO,EAAE,UAAU,EAAE,CAAA;AACrB,OAAO,EAAE,eAAe,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mobx_config.js","sourceRoot":"","sources":["../../lib/lib/mobx_config.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,SAAS,CAAC;IACN,cAAc,EAAE,OAAO;CAC1B,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function timeout(due: number | Date): Promise<void>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { lastValueFrom, timer } from 'rxjs';
|
|
38
|
+
export function timeout(due) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
40
|
+
return __generator(this, function (_a) {
|
|
41
|
+
switch (_a.label) {
|
|
42
|
+
case 0: return [4 /*yield*/, lastValueFrom(timer(due))];
|
|
43
|
+
case 1:
|
|
44
|
+
_a.sent();
|
|
45
|
+
return [2 /*return*/];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=timeout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../lib/lib/timeout.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAE5C,MAAM,UAAgB,OAAO,CAAC,GAAkB;;;;wBAC5C,qBAAM,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAA;;oBAA/B,SAA+B,CAAC;;;;;CACnC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import './mobx_config';
|
|
2
|
+
import { toJS } from 'mobx';
|
|
3
|
+
import { useRef } from 'react';
|
|
4
|
+
export function useAsLocalSource(data) {
|
|
5
|
+
var initStateCallback = function () {
|
|
6
|
+
if (Array.isArray(data)) {
|
|
7
|
+
throw new Error('Arrays is unsupported!');
|
|
8
|
+
}
|
|
9
|
+
var initState = {};
|
|
10
|
+
return initState;
|
|
11
|
+
};
|
|
12
|
+
var state = useRef(initStateCallback());
|
|
13
|
+
for (var key in data) {
|
|
14
|
+
state.current[key] = toJS(data[key]);
|
|
15
|
+
}
|
|
16
|
+
return state.current;
|
|
17
|
+
}
|
|
18
|
+
;
|
|
19
|
+
//# sourceMappingURL=useAsLocalSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAsLocalSource.js","sourceRoot":"","sources":["../../lib/lib/useAsLocalSource.tsx"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AACtB,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,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,EAAO,CAAC;QAC1B,OAAO,SAAS,CAAC;IACrB,CAAC,CAAC;IAEF,IAAM,KAAK,GAAG,MAAM,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAE1C,KAAK,IAAM,GAAG,IAAI,IAAI,EAAE;QACpB,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;KACxC;IAED,OAAO,KAAK,CAAC,OAAO,CAAC;AACzB,CAAC;AAAA,CAAC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import './mobx_config';
|
|
38
|
+
import { toJS } from 'mobx';
|
|
39
|
+
import { useLocalObservable } from 'mobx-react-lite';
|
|
40
|
+
import { useMount, useUnmount } from 'react-use';
|
|
41
|
+
import { catchError, concatMap, debounceTime, EMPTY, from, lastValueFrom, ReplaySubject, Subscription } from 'rxjs';
|
|
42
|
+
import { exhaustMapWithTrailing } from 'rxjs-exhaustmap-with-trailing';
|
|
43
|
+
import { useAsLocalSource } from './useAsLocalSource';
|
|
44
|
+
export function useAsyncExhaust(callback) {
|
|
45
|
+
var _this = this;
|
|
46
|
+
var runCallback = function () {
|
|
47
|
+
if (state.isUnmount) {
|
|
48
|
+
var resultSubjectPromise = Promise.reject(new Error("Cancelled!"));
|
|
49
|
+
resultSubjectPromise.catch(function () { return null; });
|
|
50
|
+
return resultSubjectPromise;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
var resultSubject = new ReplaySubject(0);
|
|
54
|
+
var resultSubjectPromise = lastValueFrom(resultSubject);
|
|
55
|
+
state.resultSubjectList.push({
|
|
56
|
+
subject: resultSubject,
|
|
57
|
+
promise: resultSubjectPromise
|
|
58
|
+
});
|
|
59
|
+
state.subject.next({
|
|
60
|
+
params: arguments
|
|
61
|
+
});
|
|
62
|
+
return resultSubjectPromise;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var state = useLocalObservable(function () {
|
|
66
|
+
return {
|
|
67
|
+
subscription: new Subscription(),
|
|
68
|
+
subject: new ReplaySubject(0),
|
|
69
|
+
resultSubjectList: [],
|
|
70
|
+
isUnmount: false,
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
var source = useAsLocalSource({
|
|
74
|
+
callback: callback
|
|
75
|
+
});
|
|
76
|
+
useMount(function () {
|
|
77
|
+
state.subscription.add(state.subject.pipe(debounceTime(0), exhaustMapWithTrailing(function (_a) {
|
|
78
|
+
var params = _a.params;
|
|
79
|
+
var resultSubjectList = toJS(state.resultSubjectList);
|
|
80
|
+
return from((function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
81
|
+
switch (_a.label) {
|
|
82
|
+
case 0: return [4 /*yield*/, source.callback.apply(source, params)];
|
|
83
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
84
|
+
}
|
|
85
|
+
}); }); })()).pipe(concatMap(function (result) {
|
|
86
|
+
var _loop_1 = function (resultSubject) {
|
|
87
|
+
resultSubject.subject.next(result);
|
|
88
|
+
resultSubject.subject.complete();
|
|
89
|
+
if (resultSubject.subject.closed) {
|
|
90
|
+
var index = state.resultSubjectList.findIndex(function (s) { return s === resultSubject; });
|
|
91
|
+
if (index >= 0) {
|
|
92
|
+
state.resultSubjectList.splice(index, 1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
for (var _i = 0, resultSubjectList_1 = resultSubjectList; _i < resultSubjectList_1.length; _i++) {
|
|
97
|
+
var resultSubject = resultSubjectList_1[_i];
|
|
98
|
+
_loop_1(resultSubject);
|
|
99
|
+
}
|
|
100
|
+
return EMPTY;
|
|
101
|
+
}), catchError(function (error) {
|
|
102
|
+
var _loop_2 = function (resultSubject) {
|
|
103
|
+
resultSubject.subject.error(error);
|
|
104
|
+
if (resultSubject.subject.closed) {
|
|
105
|
+
var index = state.resultSubjectList.findIndex(function (s) { return s === resultSubject; });
|
|
106
|
+
if (index >= 0) {
|
|
107
|
+
state.resultSubjectList.splice(index, 1);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
for (var _i = 0, resultSubjectList_2 = resultSubjectList; _i < resultSubjectList_2.length; _i++) {
|
|
112
|
+
var resultSubject = resultSubjectList_2[_i];
|
|
113
|
+
_loop_2(resultSubject);
|
|
114
|
+
}
|
|
115
|
+
return EMPTY;
|
|
116
|
+
}));
|
|
117
|
+
})).subscribe());
|
|
118
|
+
});
|
|
119
|
+
useUnmount(function () {
|
|
120
|
+
state.subscription.unsubscribe();
|
|
121
|
+
state.isUnmount = true;
|
|
122
|
+
var _loop_3 = function (resultSubject) {
|
|
123
|
+
resultSubject.promise.catch(function () { return null; });
|
|
124
|
+
resultSubject.subject.error(new Error("Cancelled!"));
|
|
125
|
+
if (resultSubject.subject.closed) {
|
|
126
|
+
var index = state.resultSubjectList.findIndex(function (s) { return s === resultSubject; });
|
|
127
|
+
if (index >= 0) {
|
|
128
|
+
state.resultSubjectList.splice(index, 1);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
for (var _i = 0, _a = toJS(state.resultSubjectList); _i < _a.length; _i++) {
|
|
133
|
+
var resultSubject = _a[_i];
|
|
134
|
+
_loop_3(resultSubject);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
return runCallback;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=useAsyncExhaust.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAsyncExhaust.js","sourceRoot":"","sources":["../../lib/lib/useAsyncExhaust.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,eAAe,CAAA;AACtB,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACpH,OAAO,EAAE,sBAAs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
|
4
|
+
import { catchError, distinctUntilChanged, ReplaySubject, Subscription, tap } from 'rxjs';
|
|
5
|
+
import { useEffect } from 'react';
|
|
6
|
+
import { useAsLocalSource } from './useAsLocalSource';
|
|
7
|
+
export var useAutorun = function (callback, dependencyList) {
|
|
8
|
+
var state = useLocalObservable(function () { return ({
|
|
9
|
+
subscription: new Subscription(),
|
|
10
|
+
subject: new ReplaySubject(1),
|
|
11
|
+
}); });
|
|
12
|
+
var source = useAsLocalSource({
|
|
13
|
+
callback: callback
|
|
14
|
+
});
|
|
15
|
+
useEffect(function () {
|
|
16
|
+
state.subject.next(JSON.stringify(dependencyList));
|
|
17
|
+
});
|
|
18
|
+
useMount(function () {
|
|
19
|
+
state.subscription.add(state.subject.pipe(distinctUntilChanged(), tap(function () {
|
|
20
|
+
source.callback();
|
|
21
|
+
}), catchError(function (_, caught) { return caught; })).subscribe());
|
|
22
|
+
});
|
|
23
|
+
useUnmount(function () {
|
|
24
|
+
state.subscription.unsubscribe();
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=useAutorun.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAutorun.js","sourceRoot":"","sources":["../../lib/lib/useAutorun.tsx"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AACtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAC1F,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,CAAC,IAAM,UAAU,GAAG,UAAC,QAAoB,EAAE,cAAqB;IAClE,IAAM,KAAK,GAAG,kBAAkB,CAAC,cAAM,OAAA,CAAC;QACpC,YAAY,EAAE,IAAI,YAAY,EAAE;QAChC,OAAO,EAAE,IAAI,aAAa,CAAC,CAAC,CAAC;KAChC,CAAC,EAHqC,CAGrC,CAAC,CAAA;IAEH,IAAM,MAAM,GAAG,gBAAgB,CAAC;QAC5B,QAAQ,UAAA;KACX,CAAC,CAAA;IAEF,SAAS,CAAC;QACN,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC;QACL,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CACrC,oBAAoB,EAAE,EACtB,GAAG,CAAC;YACA,MAAM,CAAC,QAAQ,EAAE,CAAC;QACtB,CAAC,CAAC,EACF,UAAU,CAAC,UAAC,CAAC,EAAE,MAAM,IAAK,OAAA,MAAM,EAAN,CAAM,CAAC,CACpC,CAAC,SAAS,EAAE,CAAC,CAAC;IACnB,CAAC,CAAC,CAAA;IAEF,UAAU,CAAC;QACP,KAAK,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;IACrC,CAAC,CAAC,CAAA;AACN,CAAC,CAAA"}
|
package/{src → lib}/index.tsx
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx-react-use-autorun",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
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",
|
|
7
7
|
"test": "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_test.ts",
|
|
8
|
-
"
|
|
8
|
+
"prepublishOnly": "npm test && npm run build"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@babel/core": "7.17.10",
|
|
@@ -43,5 +43,15 @@
|
|
|
43
43
|
"repository": {
|
|
44
44
|
"type": "git",
|
|
45
45
|
"url": "git+https://github.com/zdu-strong/mobx-react-use-autorun.git"
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"lib",
|
|
49
|
+
"dist"
|
|
50
|
+
],
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/zdu-strong/mobx-react-use-autorun/issues"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"registry": "https://registry.npmjs.org/"
|
|
46
56
|
}
|
|
47
57
|
}
|
package/.vscode/settings.json
DELETED
package/babel.config.js
DELETED
package/bin/mobx_react_build.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { execSync } from "child_process";
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
const run = async () => {
|
|
5
|
-
execSync(
|
|
6
|
-
[
|
|
7
|
-
"cross-env",
|
|
8
|
-
"TS_NODE_SKIP_PROJECT=true",
|
|
9
|
-
"ts-node bin/pre_load_configuration.ts",
|
|
10
|
-
].join(" "),
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
stdio: "inherit",
|
|
14
|
-
cwd: path.join(__dirname, ".."),
|
|
15
|
-
}
|
|
16
|
-
);
|
|
17
|
-
execSync(
|
|
18
|
-
[
|
|
19
|
-
"cross-env",
|
|
20
|
-
"tsc -p .",
|
|
21
|
-
].join(" "),
|
|
22
|
-
{
|
|
23
|
-
stdio: "inherit",
|
|
24
|
-
cwd: path.join(__dirname, ".."),
|
|
25
|
-
}
|
|
26
|
-
);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export default run();
|
package/bin/mobx_react_test.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { execSync } from "child_process";
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
const run = async () => {
|
|
5
|
-
execSync(
|
|
6
|
-
[
|
|
7
|
-
"cross-env",
|
|
8
|
-
"TS_NODE_SKIP_PROJECT=true",
|
|
9
|
-
"ts-node bin/pre_load_configuration.ts",
|
|
10
|
-
].join(" "),
|
|
11
|
-
{
|
|
12
|
-
stdio: "inherit",
|
|
13
|
-
cwd: path.join(__dirname, ".."),
|
|
14
|
-
}
|
|
15
|
-
);
|
|
16
|
-
execSync(
|
|
17
|
-
[
|
|
18
|
-
"jest --verbose --no-cache",
|
|
19
|
-
].join(" "),
|
|
20
|
-
{
|
|
21
|
-
stdio: "inherit",
|
|
22
|
-
cwd: path.join(__dirname, ".."),
|
|
23
|
-
}
|
|
24
|
-
);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export default run();
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { execSync } from 'child_process';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
const run = async () => {
|
|
6
|
-
await deletePackageLockFile();
|
|
7
|
-
await deleteBuildFolder();
|
|
8
|
-
execSync(
|
|
9
|
-
[
|
|
10
|
-
"cross-env",
|
|
11
|
-
"npm_config_package_lock=false",
|
|
12
|
-
"npm install",
|
|
13
|
-
].join(" "),
|
|
14
|
-
{
|
|
15
|
-
stdio: "inherit",
|
|
16
|
-
}
|
|
17
|
-
);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const deletePackageLockFile = async () => {
|
|
21
|
-
const filePathOfPackageLockFile = path.join(__dirname, "..", "package-lock.json");
|
|
22
|
-
await fs.promises.rm(filePathOfPackageLockFile, { recursive: true, force: true });
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const deleteBuildFolder = async () => {
|
|
26
|
-
const folderPath = path.join(__dirname, "..", "dist");
|
|
27
|
-
await fs.promises.rm(folderPath, { recursive: true, force: true });
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export default run();
|
package/jest.config.ts
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* For a detailed explanation regarding each configuration property and type check, visit:
|
|
3
|
-
* https://jestjs.io/docs/configuration
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
// All imported modules in your tests should be mocked automatically
|
|
8
|
-
// automock: false,
|
|
9
|
-
|
|
10
|
-
// Stop running tests after `n` failures
|
|
11
|
-
// bail: 0,
|
|
12
|
-
|
|
13
|
-
// The directory where Jest should store its cached dependency information
|
|
14
|
-
// cacheDirectory: "C:\\Users\\zdu\\AppData\\Local\\Temp\\jest",
|
|
15
|
-
|
|
16
|
-
// Automatically clear mock calls, instances, contexts and results before every test
|
|
17
|
-
clearMocks: true,
|
|
18
|
-
|
|
19
|
-
// Indicates whether the coverage information should be collected while executing the test
|
|
20
|
-
collectCoverage: true,
|
|
21
|
-
|
|
22
|
-
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
23
|
-
// collectCoverageFrom: undefined,
|
|
24
|
-
|
|
25
|
-
// The directory where Jest should output its coverage files
|
|
26
|
-
coverageDirectory: "coverage",
|
|
27
|
-
|
|
28
|
-
// An array of regexp pattern strings used to skip coverage collection
|
|
29
|
-
// coveragePathIgnorePatterns: [
|
|
30
|
-
// "\\\\node_modules\\\\"
|
|
31
|
-
// ],
|
|
32
|
-
|
|
33
|
-
// Indicates which provider should be used to instrument code for coverage
|
|
34
|
-
// coverageProvider: "babel",
|
|
35
|
-
|
|
36
|
-
// A list of reporter names that Jest uses when writing coverage reports
|
|
37
|
-
// coverageReporters: [
|
|
38
|
-
// "json",
|
|
39
|
-
// "text",
|
|
40
|
-
// "lcov",
|
|
41
|
-
// "clover"
|
|
42
|
-
// ],
|
|
43
|
-
|
|
44
|
-
// An object that configures minimum threshold enforcement for coverage results
|
|
45
|
-
// coverageThreshold: undefined,
|
|
46
|
-
|
|
47
|
-
// A path to a custom dependency extractor
|
|
48
|
-
// dependencyExtractor: undefined,
|
|
49
|
-
|
|
50
|
-
// Make calling deprecated APIs throw helpful error messages
|
|
51
|
-
// errorOnDeprecated: false,
|
|
52
|
-
|
|
53
|
-
// The default configuration for fake timers
|
|
54
|
-
// fakeTimers: {
|
|
55
|
-
// "enableGlobally": false
|
|
56
|
-
// },
|
|
57
|
-
|
|
58
|
-
// Force coverage collection from ignored files using an array of glob patterns
|
|
59
|
-
// forceCoverageMatch: [],
|
|
60
|
-
|
|
61
|
-
// A path to a module which exports an async function that is triggered once before all test suites
|
|
62
|
-
// globalSetup: undefined,
|
|
63
|
-
|
|
64
|
-
// A path to a module which exports an async function that is triggered once after all test suites
|
|
65
|
-
// globalTeardown: undefined,
|
|
66
|
-
|
|
67
|
-
// A set of global variables that need to be available in all test environments
|
|
68
|
-
// globals: {},
|
|
69
|
-
|
|
70
|
-
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
71
|
-
// maxWorkers: "50%",
|
|
72
|
-
|
|
73
|
-
// An array of directory names to be searched recursively up from the requiring module's location
|
|
74
|
-
// moduleDirectories: [
|
|
75
|
-
// "node_modules"
|
|
76
|
-
// ],
|
|
77
|
-
|
|
78
|
-
// An array of file extensions your modules use
|
|
79
|
-
// moduleFileExtensions: [
|
|
80
|
-
// "js",
|
|
81
|
-
// "mjs",
|
|
82
|
-
// "cjs",
|
|
83
|
-
// "jsx",
|
|
84
|
-
// "ts",
|
|
85
|
-
// "tsx",
|
|
86
|
-
// "json",
|
|
87
|
-
// "node"
|
|
88
|
-
// ],
|
|
89
|
-
|
|
90
|
-
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
91
|
-
// moduleNameMapper: {},
|
|
92
|
-
|
|
93
|
-
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
94
|
-
// modulePathIgnorePatterns: [],
|
|
95
|
-
|
|
96
|
-
// Activates notifications for test results
|
|
97
|
-
// notify: false,
|
|
98
|
-
|
|
99
|
-
// An enum that specifies notification mode. Requires { notify: true }
|
|
100
|
-
// notifyMode: "failure-change",
|
|
101
|
-
|
|
102
|
-
// A preset that is used as a base for Jest's configuration
|
|
103
|
-
// preset: undefined,
|
|
104
|
-
|
|
105
|
-
// Run tests from one or more projects
|
|
106
|
-
// projects: undefined,
|
|
107
|
-
|
|
108
|
-
// Use this configuration option to add custom reporters to Jest
|
|
109
|
-
// reporters: undefined,
|
|
110
|
-
|
|
111
|
-
// Automatically reset mock state before every test
|
|
112
|
-
// resetMocks: false,
|
|
113
|
-
|
|
114
|
-
// Reset the module registry before running each individual test
|
|
115
|
-
// resetModules: false,
|
|
116
|
-
|
|
117
|
-
// A path to a custom resolver
|
|
118
|
-
// resolver: undefined,
|
|
119
|
-
|
|
120
|
-
// Automatically restore mock state and implementation before every test
|
|
121
|
-
// restoreMocks: false,
|
|
122
|
-
|
|
123
|
-
// The root directory that Jest should scan for tests and modules within
|
|
124
|
-
// rootDir: undefined,
|
|
125
|
-
|
|
126
|
-
// A list of paths to directories that Jest should use to search for files in
|
|
127
|
-
// roots: [
|
|
128
|
-
// "<rootDir>"
|
|
129
|
-
// ],
|
|
130
|
-
|
|
131
|
-
// Allows you to use a custom runner instead of Jest's default test runner
|
|
132
|
-
// runner: "jest-runner",
|
|
133
|
-
|
|
134
|
-
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
135
|
-
// setupFiles: [],
|
|
136
|
-
|
|
137
|
-
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
138
|
-
// setupFilesAfterEnv: [],
|
|
139
|
-
|
|
140
|
-
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
|
141
|
-
// slowTestThreshold: 5,
|
|
142
|
-
|
|
143
|
-
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
144
|
-
// snapshotSerializers: [],
|
|
145
|
-
|
|
146
|
-
// The test environment that will be used for testing
|
|
147
|
-
testEnvironment: "jsdom",
|
|
148
|
-
|
|
149
|
-
// Options that will be passed to the testEnvironment
|
|
150
|
-
// testEnvironmentOptions: {},
|
|
151
|
-
|
|
152
|
-
// Adds a location field to test results
|
|
153
|
-
// testLocationInResults: false,
|
|
154
|
-
|
|
155
|
-
// The glob patterns Jest uses to detect test files
|
|
156
|
-
// testMatch: [
|
|
157
|
-
// "**/__tests__/**/*.[jt]s?(x)",
|
|
158
|
-
// "**/?(*.)+(spec|test).[tj]s?(x)"
|
|
159
|
-
// ],
|
|
160
|
-
|
|
161
|
-
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
162
|
-
// testPathIgnorePatterns: [
|
|
163
|
-
// "\\\\node_modules\\\\"
|
|
164
|
-
// ],
|
|
165
|
-
|
|
166
|
-
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
167
|
-
// testRegex: [],
|
|
168
|
-
|
|
169
|
-
// This option allows the use of a custom results processor
|
|
170
|
-
// testResultsProcessor: undefined,
|
|
171
|
-
|
|
172
|
-
// This option allows use of a custom test runner
|
|
173
|
-
// testRunner: "jest-circus/runner",
|
|
174
|
-
|
|
175
|
-
// A map from regular expressions to paths to transformers
|
|
176
|
-
// transform: undefined,
|
|
177
|
-
|
|
178
|
-
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
179
|
-
// transformIgnorePatterns: [
|
|
180
|
-
// "\\\\node_modules\\\\",
|
|
181
|
-
// "\\.pnp\\.[^\\\\]+$"
|
|
182
|
-
// ],
|
|
183
|
-
|
|
184
|
-
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
185
|
-
// unmockedModulePathPatterns: undefined,
|
|
186
|
-
|
|
187
|
-
// Indicates whether each individual test should be reported during the run
|
|
188
|
-
// verbose: undefined,
|
|
189
|
-
|
|
190
|
-
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
191
|
-
// watchPathIgnorePatterns: [],
|
|
192
|
-
|
|
193
|
-
// Whether to use watchman for file crawling
|
|
194
|
-
// watchman: true,
|
|
195
|
-
};
|
package/test/timeout.test.tsx
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { timeout } from '../src/index'
|
|
2
|
-
|
|
3
|
-
let startDate = null as Date | null;
|
|
4
|
-
|
|
5
|
-
test('Expect timeout as a promise to return after one second', async () => {
|
|
6
|
-
await timeout(1000)
|
|
7
|
-
expect(new Date().getTime()).toBeGreaterThanOrEqual(startDate.getTime())
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
beforeAll(() => {
|
|
11
|
-
startDate = new Date();
|
|
12
|
-
})
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useAsLocalSource } from '../src/index'
|
|
2
|
-
import { renderHook } from '@testing-library/react-hooks'
|
|
3
|
-
|
|
4
|
-
test('Expect useAsLocalSource to return the passed in value', () => {
|
|
5
|
-
const { result } = renderHook((props) => useAsLocalSource(props), {
|
|
6
|
-
initialProps: { people: { name: 'tom' } }
|
|
7
|
-
});
|
|
8
|
-
expect(result.current.people.name).toEqual('tom')
|
|
9
|
-
})
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { useAsyncExhaust, timeout } from '../src/index'
|
|
2
|
-
import { renderHook } from '@testing-library/react-hooks'
|
|
3
|
-
|
|
4
|
-
test('Expect useAsyncExhaust to run only once when it is called consecutively', async () => {
|
|
5
|
-
let runTimes = 0;
|
|
6
|
-
const { result } = renderHook(() => useAsyncExhaust(async () => {
|
|
7
|
-
await timeout(1000);
|
|
8
|
-
runTimes++;
|
|
9
|
-
}));
|
|
10
|
-
await Promise.all([
|
|
11
|
-
result.current(),
|
|
12
|
-
result.current(),
|
|
13
|
-
result.current(),
|
|
14
|
-
result.current(),
|
|
15
|
-
result.current(),
|
|
16
|
-
])
|
|
17
|
-
expect(runTimes).toEqual(1)
|
|
18
|
-
})
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useAutorun } from '../src/index'
|
|
2
|
-
import { renderHook } from '@testing-library/react-hooks'
|
|
3
|
-
|
|
4
|
-
test('Expect useAutorun to take effect', () => {
|
|
5
|
-
let runTimes = 0;
|
|
6
|
-
const { rerender } = renderHook((props) => useAutorun(() => {
|
|
7
|
-
runTimes++;
|
|
8
|
-
}, [props.people]), {
|
|
9
|
-
initialProps: { people: { name: 'tom', age: 16 } }
|
|
10
|
-
});
|
|
11
|
-
expect(runTimes).toEqual(1)
|
|
12
|
-
rerender({ people: { name: 'tom', age: 16 } })
|
|
13
|
-
expect(runTimes).toEqual(1)
|
|
14
|
-
rerender({ people: { name: 'tom', age: 17 } })
|
|
15
|
-
rerender({ people: { name: 'tom', age: 18 } })
|
|
16
|
-
expect(runTimes).toEqual(3)
|
|
17
|
-
})
|
package/tsconfig.json
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"outDir": "./dist/",
|
|
4
|
-
"target": "es5",
|
|
5
|
-
"lib": [
|
|
6
|
-
"dom",
|
|
7
|
-
"dom.iterable",
|
|
8
|
-
"esnext"
|
|
9
|
-
],
|
|
10
|
-
"allowJs": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"esModuleInterop": true,
|
|
13
|
-
"allowSyntheticDefaultImports": true,
|
|
14
|
-
"strict": true,
|
|
15
|
-
"forceConsistentCasingInFileNames": true,
|
|
16
|
-
"noFallthroughCasesInSwitch": true,
|
|
17
|
-
"module": "esnext",
|
|
18
|
-
"moduleResolution": "node",
|
|
19
|
-
"resolveJsonModule": true,
|
|
20
|
-
"isolatedModules": true,
|
|
21
|
-
"noEmit": false,
|
|
22
|
-
"jsx": "react-jsx",
|
|
23
|
-
"sourceMap": true,
|
|
24
|
-
"declaration": true,
|
|
25
|
-
},
|
|
26
|
-
"include": [
|
|
27
|
-
"src",
|
|
28
|
-
]
|
|
29
|
-
}
|