@chaomingd/store 2.0.7

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.
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.calcComputedState = calcComputedState;
7
+ exports.calcDiffKeys = calcDiffKeys;
8
+ exports.execWatchHandler = execWatchHandler;
9
+ function calcDiffKeys(obj1, obj2, keys) {
10
+ const diffKeysMap = {};
11
+ let diff = false;
12
+ keys.forEach(key => {
13
+ // @ts-ignore
14
+ if (!Object.is(obj1[key], obj2[key])) {
15
+ diffKeysMap[key] = true;
16
+ diff = true;
17
+ }
18
+ });
19
+ return {
20
+ diffKeysMap,
21
+ diff
22
+ };
23
+ }
24
+ function calcComputedState({
25
+ prevState,
26
+ nextState,
27
+ computed
28
+ }) {
29
+ if (computed) {
30
+ computed.reduce((currentNextState, computedItem) => {
31
+ let partialState;
32
+ if (typeof computedItem === 'function') {
33
+ partialState = computedItem(currentNextState, prevState);
34
+ } else {
35
+ const {
36
+ diffKeysMap,
37
+ diff
38
+ } = calcDiffKeys(prevState, currentNextState, computedItem.keys);
39
+ if (diff) {
40
+ partialState = computedItem.hander(currentNextState, diffKeysMap, prevState);
41
+ }
42
+ }
43
+ if (partialState) {
44
+ Object.assign(currentNextState, partialState);
45
+ }
46
+ return currentNextState;
47
+ }, nextState);
48
+ }
49
+ return nextState;
50
+ }
51
+ function execWatchHandler({
52
+ prevState,
53
+ nextState,
54
+ watch
55
+ }) {
56
+ if (watch) {
57
+ watch.forEach(watchItem => {
58
+ if (watchItem.keys) {
59
+ const {
60
+ diffKeysMap,
61
+ diff
62
+ } = calcDiffKeys(prevState, nextState, watchItem.keys);
63
+ if (diff) {
64
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
65
+ watchItem.hander && watchItem.hander(nextState, diffKeysMap, prevState);
66
+ }
67
+ }
68
+ });
69
+ }
70
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@chaomingd/store",
3
+ "version": "2.0.7",
4
+ "description": "store of laf",
5
+ "keywords": [],
6
+ "license": "MIT",
7
+ "main": "dist/lib/index.js",
8
+ "module": "dist/esm/index.js",
9
+ "typings": "dist/esm/index.d.ts",
10
+ "files": [
11
+ "dist",
12
+ "compiled"
13
+ ],
14
+ "dependencies": {
15
+ "@types/use-sync-external-store": "^0.0.6",
16
+ "use-sync-external-store": "^1.2.2",
17
+ "@chaomingd/utils": "0.0.17"
18
+ },
19
+ "devDependencies": {
20
+ "father": "^4.5.0"
21
+ },
22
+ "peerDependencies": {
23
+ "ahooks": ">=3.0.0",
24
+ "react": ">=16.9.0",
25
+ "react-dom": ">=16.9.0"
26
+ },
27
+ "authors": [],
28
+ "publishConfig": {
29
+ "access": "public",
30
+ "registry": "https://registry.npmjs.org/"
31
+ },
32
+ "scripts": {
33
+ "build": "father build",
34
+ "build:deps": "father prebundle",
35
+ "dev": "father dev"
36
+ }
37
+ }