Skip to content

Commit 049347d

Browse files
committed
chore: done
1 parent a3d660f commit 049347d

File tree

11 files changed

+697
-67
lines changed

11 files changed

+697
-67
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem.
25+
26+
**Desktop (please complete the following information):**
27+
- OS: [e.g. iOS]
28+
- Browser [e.g. chrome, safari]
29+
- Version [e.g. 22]
30+
31+
**Smartphone (please complete the following information):**
32+
- Device: [e.g. iPhone6]
33+
- OS: [e.g. iOS8.1]
34+
- Browser [e.g. stock browser, safari]
35+
- Version [e.g. 22]
36+
37+
**Additional context**
38+
Add any other context about the problem here.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

.github/workflows/npm-publish.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3+
4+
name: publish
5+
6+
on:
7+
push:
8+
branches: [master]
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/setup-node@v1
16+
with:
17+
node-version: 12
18+
- run: yarn
19+
- run: yarn test
20+
21+
publish-npm:
22+
needs: build
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v2
26+
- uses: actions/setup-node@v1
27+
with:
28+
node-version: 12
29+
registry-url: https://registry.npmjs.org/
30+
- run: |
31+
git config --local user.email "[email protected]"
32+
git config --local user.name "fupengl"
33+
- run: yarn
34+
- run: npm publish
35+
env:
36+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
37+
- name: Push changes
38+
uses: ad-m/github-push-action@master
39+
with:
40+
github_token: ${{ secrets.GITHUB_TOKEN }}
41+
branch: ${{ github.ref }}
42+
43+
publish-gpr:
44+
needs: build
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v2
48+
- uses: actions/setup-node@v1
49+
with:
50+
node-version: 12
51+
registry-url: https://npm.pkg.github.com/
52+
- run: yarn
53+
- run: npm publish
54+
env:
55+
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

.stanrc.ts

-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,5 @@ export default {
22
bundler: 'babel',
33
esm: true,
44
cjs: true,
5-
umd: {
6-
minify: true,
7-
runtimeHelpers: false,
8-
},
95
runtimeHelpers: true,
106
};

package.json

+57-26
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,28 @@
22
"name": "@planjs/react-utils",
33
"version": "0.0.1",
44
"description": "React tool collection",
5+
"keywords": [],
6+
"homepage": "https://github.com/planjs/react-utils#readme",
7+
"bugs": {
8+
"url": "https://github.com/planjs/react-utils/issues"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/planjs/react-utils.git"
13+
},
14+
"license": "MIT",
15+
"author": {
16+
"name": "fupengl",
17+
"email": "[email protected]",
18+
"url": "https://github.com/fupengl"
19+
},
520
"sideEffects": false,
621
"main": "lib/index.js",
722
"module": "es/index.js",
8-
"umd:main": "lib/index.umd.js",
9-
"unpkg": "lib/index.umd.min.js",
1023
"typings": "typings/index.d.ts",
1124
"files": [
1225
"lib",
1326
"es",
14-
"dist",
1527
"typings"
1628
],
1729
"scripts": {
@@ -22,48 +34,67 @@
2234
"lint:fix": "eslint --fix --ext js,jsx,ts,tsx src",
2335
"test": "jest"
2436
},
25-
"repository": {
26-
"type": "git",
27-
"url": "git+https://github.com/planjs/react-utils.git"
37+
"husky": {
38+
"hooks": {
39+
"pre-commit": "lint-staged",
40+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
41+
}
2842
},
29-
"keywords": [],
30-
"author": {
31-
"name": "fupengl",
32-
"email": "[email protected]",
33-
"url": "https://github.com/fupengl"
43+
"commitlint": {
44+
"extends": [
45+
"@commitlint/config-conventional"
46+
]
3447
},
35-
"license": "MIT",
36-
"bugs": {
37-
"url": "https://github.com/planjs/react-utils/issues"
48+
"lint-staged": {
49+
"*.{js,ts,tsx}": [
50+
"eslint --fix",
51+
"git add"
52+
],
53+
"*.{json,json,css,scss}": [
54+
"prettier --write",
55+
"git add"
56+
],
57+
"package.json": [
58+
"npx sort-package-json",
59+
"git add"
60+
]
3861
},
39-
"homepage": "https://github.com/planjs/react-utils#readme",
40-
"publishConfig": {
41-
"access": "public"
62+
"config": {
63+
"commitizen": {
64+
"path": "./node_modules/cz-conventional-changelog"
65+
}
4266
},
4367
"dependencies": {
44-
"fast-deep-equal": "^3.1.3",
4568
"@babel/runtime": "^7.12.5",
4669
"@planjs/utils": "^1.8.4",
70+
"fast-deep-equal": "^3.1.3",
4771
"resize-observer-polyfill": "^1.5.1"
4872
},
4973
"devDependencies": {
74+
"@commitlint/cli": "^9.1.2",
75+
"@commitlint/config-conventional": "^11.0.0",
5076
"@planjs/fabric": "^0.0.76",
51-
"typescript": "4.1.5",
52-
"stan-builder": "^0.9.13",
53-
"react": "16.14.0",
54-
"react-dom": "16.14.0",
55-
"@types/node": "^16.3.3",
56-
"@types/react": "^16.9.56",
57-
"@types/react-dom": "^16.9.14",
5877
"@testing-library/react": "^12.0.0",
5978
"@testing-library/react-hooks": "^7.0.1",
6079
"@types/jest": "^26.0.24",
80+
"@types/node": "^16.3.3",
81+
"@types/react": "^16.9.56",
82+
"@types/react-dom": "^16.9.14",
83+
"husky": "^4.2.5",
6184
"jest": "^27.0.6",
85+
"lint-staged": "^10.2.13",
86+
"react": "16.14.0",
87+
"react-dom": "16.14.0",
88+
"stan-builder": "^0.9.14",
89+
"standard-version": "^9.0.0",
6290
"ts-jest": "^27.0.3",
63-
"standard-version": "^9.0.0"
91+
"typescript": "4.1.5"
6492
},
6593
"peerDependencies": {
6694
"react": ">16.8.0",
6795
"react-dom": ">16.8.0"
96+
},
97+
"publishConfig": {
98+
"access": "public"
6899
}
69100
}

src/hooks/index.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
// factory
2+
export { default as createStateContext } from './createStateContext';
3+
export { default as createGlobalState } from './createGlobalState';
4+
5+
// hooks
16
export { default as useLifecycles } from './useLifecycles';
27
export { default as useMount } from './useMount';
38
export { default as useUnmount } from './useUnmount';
49
export { default as useMountedState } from './useMountedState';
510
export { default as usePersistFn } from './usePersistFn';
611
export { default as useUpdateEffect } from './useUpdateEffect';
712
export { default as useForceUpdate } from './useForceUpdate';
8-
export { default as createStateContext } from './createStateContext';
9-
export { default as createGlobalState } from './createGlobalState';
1013
export { default as useDeepEffect } from './useDeepEffect';
1114

1215
export { default as useInterval } from './useInterval';

src/hooks/typings.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export type FnReturningPromise = (...args: any[]) => Promise<any>;
2+
23
export type PromiseType<P extends Promise<any>> = P extends Promise<infer T> ? T : never;

src/hooks/useDeepEffect.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useRef, useEffect } from 'react';
22
import type { DependencyList, EffectCallback } from 'react';
3-
import deepEqual from 'fast-deep-equal/react';
43
import { isPrimitive } from '@planjs/utils';
4+
import isDeepEqual from '../utils/isDeepEqual';
55

66
const warnDeps = (dependencies: DependencyList) => {
77
if (dependencies.length === 0) {
@@ -17,7 +17,7 @@ function useDeepCompareMemoize(value: DependencyList) {
1717
const ref = useRef<DependencyList>();
1818
const signalRef = useRef<number>(0);
1919

20-
if (!deepEqual(value, ref.current)) {
20+
if (!isDeepEqual(value, ref.current)) {
2121
ref.current = value;
2222
signalRef.current += 1;
2323
}

src/hooks/useVisibleObserve.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@ export default function useVisibleObserve(domId: string, rootId: string, flag?:
199199
const [visible, setVisible] = useState(false);
200200

201201
useEffect(() => {
202-
// @ts-ignore
203-
const visibleObserve = new VisibleObserve(domId, rootId, setVisible);
202+
const visibleObserve = new VisibleObserve(domId, rootId, (active) => {
203+
setVisible(!!active);
204+
});
204205

205206
visibleObserve.observe();
206207

src/utils/isDeepEqual.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import isDeepEqualReact from 'fast-deep-equal/react';
2+
3+
export default isDeepEqualReact;

0 commit comments

Comments
 (0)