Skip to content

Commit

Permalink
chore: done
Browse files Browse the repository at this point in the history
  • Loading branch information
fupengl committed Jul 22, 2021
1 parent a3d660f commit 049347d
Show file tree
Hide file tree
Showing 11 changed files with 697 additions and 67 deletions.
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
55 changes: 55 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: publish

on:
push:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
- run: yarn
- run: yarn test

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: |
git config --local user.email "[email protected]"
git config --local user.name "fupengl"
- run: yarn
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}

publish-gpr:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://npm.pkg.github.com/
- run: yarn
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
4 changes: 0 additions & 4 deletions .stanrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@ export default {
bundler: 'babel',
esm: true,
cjs: true,
umd: {
minify: true,
runtimeHelpers: false,
},
runtimeHelpers: true,
};
83 changes: 57 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@
"name": "@planjs/react-utils",
"version": "0.0.1",
"description": "React tool collection",
"keywords": [],
"homepage": "https://github.com/planjs/react-utils#readme",
"bugs": {
"url": "https://github.com/planjs/react-utils/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/planjs/react-utils.git"
},
"license": "MIT",
"author": {
"name": "fupengl",
"email": "[email protected]",
"url": "https://github.com/fupengl"
},
"sideEffects": false,
"main": "lib/index.js",
"module": "es/index.js",
"umd:main": "lib/index.umd.js",
"unpkg": "lib/index.umd.min.js",
"typings": "typings/index.d.ts",
"files": [
"lib",
"es",
"dist",
"typings"
],
"scripts": {
Expand All @@ -22,48 +34,67 @@
"lint:fix": "eslint --fix --ext js,jsx,ts,tsx src",
"test": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/planjs/react-utils.git"
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"keywords": [],
"author": {
"name": "fupengl",
"email": "[email protected]",
"url": "https://github.com/fupengl"
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"license": "MIT",
"bugs": {
"url": "https://github.com/planjs/react-utils/issues"
"lint-staged": {
"*.{js,ts,tsx}": [
"eslint --fix",
"git add"
],
"*.{json,json,css,scss}": [
"prettier --write",
"git add"
],
"package.json": [
"npx sort-package-json",
"git add"
]
},
"homepage": "https://github.com/planjs/react-utils#readme",
"publishConfig": {
"access": "public"
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"dependencies": {
"fast-deep-equal": "^3.1.3",
"@babel/runtime": "^7.12.5",
"@planjs/utils": "^1.8.4",
"fast-deep-equal": "^3.1.3",
"resize-observer-polyfill": "^1.5.1"
},
"devDependencies": {
"@commitlint/cli": "^9.1.2",
"@commitlint/config-conventional": "^11.0.0",
"@planjs/fabric": "^0.0.76",
"typescript": "4.1.5",
"stan-builder": "^0.9.13",
"react": "16.14.0",
"react-dom": "16.14.0",
"@types/node": "^16.3.3",
"@types/react": "^16.9.56",
"@types/react-dom": "^16.9.14",
"@testing-library/react": "^12.0.0",
"@testing-library/react-hooks": "^7.0.1",
"@types/jest": "^26.0.24",
"@types/node": "^16.3.3",
"@types/react": "^16.9.56",
"@types/react-dom": "^16.9.14",
"husky": "^4.2.5",
"jest": "^27.0.6",
"lint-staged": "^10.2.13",
"react": "16.14.0",
"react-dom": "16.14.0",
"stan-builder": "^0.9.14",
"standard-version": "^9.0.0",
"ts-jest": "^27.0.3",
"standard-version": "^9.0.0"
"typescript": "4.1.5"
},
"peerDependencies": {
"react": ">16.8.0",
"react-dom": ">16.8.0"
},
"publishConfig": {
"access": "public"
}
}
7 changes: 5 additions & 2 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// factory
export { default as createStateContext } from './createStateContext';
export { default as createGlobalState } from './createGlobalState';

// hooks
export { default as useLifecycles } from './useLifecycles';
export { default as useMount } from './useMount';
export { default as useUnmount } from './useUnmount';
export { default as useMountedState } from './useMountedState';
export { default as usePersistFn } from './usePersistFn';
export { default as useUpdateEffect } from './useUpdateEffect';
export { default as useForceUpdate } from './useForceUpdate';
export { default as createStateContext } from './createStateContext';
export { default as createGlobalState } from './createGlobalState';
export { default as useDeepEffect } from './useDeepEffect';

export { default as useInterval } from './useInterval';
Expand Down
1 change: 1 addition & 0 deletions src/hooks/typings.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export type FnReturningPromise = (...args: any[]) => Promise<any>;

export type PromiseType<P extends Promise<any>> = P extends Promise<infer T> ? T : never;
4 changes: 2 additions & 2 deletions src/hooks/useDeepEffect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useRef, useEffect } from 'react';
import type { DependencyList, EffectCallback } from 'react';
import deepEqual from 'fast-deep-equal/react';
import { isPrimitive } from '@planjs/utils';
import isDeepEqual from '../utils/isDeepEqual';

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

if (!deepEqual(value, ref.current)) {
if (!isDeepEqual(value, ref.current)) {
ref.current = value;
signalRef.current += 1;
}
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useVisibleObserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,9 @@ export default function useVisibleObserve(domId: string, rootId: string, flag?:
const [visible, setVisible] = useState(false);

useEffect(() => {
// @ts-ignore
const visibleObserve = new VisibleObserve(domId, rootId, setVisible);
const visibleObserve = new VisibleObserve(domId, rootId, (active) => {
setVisible(!!active);
});

visibleObserve.observe();

Expand Down
3 changes: 3 additions & 0 deletions src/utils/isDeepEqual.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import isDeepEqualReact from 'fast-deep-equal/react';

export default isDeepEqualReact;
Loading

0 comments on commit 049347d

Please sign in to comment.