~repos /atoms-state
git clone https://pyrossh.dev/repos/atoms-state.git
Simple State management for react
83ed933f
—
pyros2097 4 years ago
merge
- .github/workflows/size.yml +0 -12
- README.md +2 -2
- package.json +8 -26
- src/index.ts +1 -4
.github/workflows/size.yml
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
name: size
|
|
2
|
-
on: [pull_request]
|
|
3
|
-
jobs:
|
|
4
|
-
size:
|
|
5
|
-
runs-on: ubuntu-latest
|
|
6
|
-
env:
|
|
7
|
-
CI_JOB_NUMBER: 1
|
|
8
|
-
steps:
|
|
9
|
-
- uses: actions/checkout@v1
|
|
10
|
-
- uses: andresz1/size-limit-action@v1
|
|
11
|
-
with:
|
|
12
|
-
github_token: ${{ secrets.GITHUB_TOKEN }}
|
README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# atoms
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/
|
|
3
|
+
[](https://www.npmjs.com/package/atoms-state)
|
|
4
4
|
|
|
5
5
|
A simple statemanagement library for react.
|
|
6
6
|
|
|
7
|
-
`npm i
|
|
7
|
+
`npm i atoms-state`
|
|
8
8
|
|
|
9
9
|
## Usage
|
|
10
10
|
|
package.json
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
+
"name": "atoms-state",
|
|
3
|
+
"author": "pyros.sh",
|
|
2
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
3
5
|
"license": "MIT",
|
|
4
6
|
"main": "dist/index.js",
|
|
5
7
|
"typings": "dist/index.d.ts",
|
|
@@ -15,13 +17,12 @@
|
|
|
15
17
|
},
|
|
16
18
|
"scripts": {
|
|
17
19
|
"start": "tsdx watch",
|
|
18
|
-
"build": "
|
|
20
|
+
"build": "tsc src/*.* -d --target esnext --module commonjs --moduleResolution node --outDir dist",
|
|
19
21
|
"test": "tsdx test",
|
|
20
22
|
"lint": "tsdx lint --fix",
|
|
21
|
-
"prepare": "
|
|
23
|
+
"prepare": "npm run build",
|
|
22
24
|
"size": "size-limit",
|
|
23
|
-
"analyze": "size-limit --why"
|
|
25
|
+
"analyze": "size-limit --why"
|
|
24
|
-
"deploy": "np"
|
|
25
26
|
},
|
|
26
27
|
"peerDependencies": {
|
|
27
28
|
"react": "*"
|
|
@@ -32,34 +33,15 @@
|
|
|
32
33
|
}
|
|
33
34
|
},
|
|
34
35
|
"prettier": {
|
|
35
|
-
"printWidth":
|
|
36
|
+
"printWidth": 160,
|
|
36
37
|
"semi": true,
|
|
37
38
|
"singleQuote": true,
|
|
38
39
|
"trailingComma": "es5"
|
|
39
40
|
},
|
|
40
|
-
"repository": {
|
|
41
|
-
"url": "git@github.com:pyros2097/atoms.git"
|
|
42
|
-
},
|
|
43
|
-
"name": "@pyros2097/atoms",
|
|
44
|
-
"author": "pyros2097",
|
|
45
|
-
"module": "dist/atoms.esm.js",
|
|
46
|
-
"size-limit": [
|
|
47
|
-
{
|
|
48
|
-
"path": "dist/atoms.cjs.production.min.js",
|
|
49
|
-
"limit": "10 KB"
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
"path": "dist/atoms.esm.js",
|
|
53
|
-
"limit": "10 KB"
|
|
54
|
-
}
|
|
55
|
-
],
|
|
56
41
|
"devDependencies": {
|
|
57
|
-
"@size-limit/preset-small-lib": "^4.10.2",
|
|
58
42
|
"@types/react": "17.0.2",
|
|
59
43
|
"husky": "^6.0.0",
|
|
60
|
-
"np": "^7.4.0",
|
|
61
44
|
"react": "17.0.2",
|
|
62
|
-
"size-limit": "^4.10.2",
|
|
63
45
|
"tsdx": "^0.14.1",
|
|
64
46
|
"tslib": "^2.1.0",
|
|
65
47
|
"typescript": "^4.2.3"
|
|
@@ -68,4 +50,4 @@
|
|
|
68
50
|
"**/@typescript-eslint/eslint-plugin": "^4.1.1",
|
|
69
51
|
"**/@typescript-eslint/parser": "^4.1.1"
|
|
70
52
|
}
|
|
71
|
-
}
|
|
53
|
+
}
|
src/index.ts
CHANGED
|
@@ -114,10 +114,7 @@ export const useAsyncAtom = <P, S>(a: AsyncAtom<P, S>, params: P) => {
|
|
|
114
114
|
type PromiseFunc<S, P> = (p: P) => Promise<S>;
|
|
115
115
|
|
|
116
116
|
const usePromiseCache: Map<Function, Map<string, any>> = new Map();
|
|
117
|
-
export const usePromise = <S, P>(
|
|
118
|
-
fn: PromiseFunc<S, P>,
|
|
119
|
-
params: P
|
|
120
|
-
): [S | null, (v: S) => void] => {
|
|
117
|
+
export const usePromise = <S, P>(fn: PromiseFunc<S, P>, params: P): [S | null, (v: S) => void] => {
|
|
121
118
|
const [data, setData] = useState<boolean>(false);
|
|
122
119
|
const fnCache = usePromiseCache.get(fn) || new Map();
|
|
123
120
|
if (!usePromiseCache.get(fn)) {
|