Skip to content

Commit 8bcbc12

Browse files
authored
Merge pull request #28 from react-restart/docs2
Docs, finally
2 parents 65f7cc9 + 6008849 commit 8bcbc12

File tree

21 files changed

+15019
-25
lines changed

21 files changed

+15019
-25
lines changed

.github/workflows/deploy-docs.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Deploy Documentation
2+
on:
3+
push:
4+
branches:
5+
- master
6+
jobs:
7+
build_docs:
8+
name: Build and Deploy Documentation
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checking out Repository
12+
uses: actions/checkout@v1
13+
- name: Setup Node.js
14+
uses: actions/setup-node@v1
15+
- name: Install Dependencies
16+
run: yarn bootstrap
17+
- name: Build and Deploy Production Files
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
run: yarn deploy-docs

.github/workflows/test.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Run Tests
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
jobs:
10+
test:
11+
name: Run Testing Suite
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checking out Repository
15+
uses: actions/checkout@v2
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v1
18+
with:
19+
node-version: 12.x
20+
- name: Install Dependencies
21+
run: yarn bootstrap
22+
- name: Run Tests
23+
run: yarn test
24+
- name: Build Project
25+
run: yarn build
26+
- name: Upload Test Coverage to CodeCov
27+
uses: codecov/[email protected]
28+
with:
29+
token: ${{ secrets.CODECOV_TOKEN }}

.travis.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
},
1919
"homepage": "https://github.com/react-restart/hooks#readme",
2020
"scripts": {
21+
"bootstrap": "yarn && yarn --cwd www",
2122
"test": "jest --coverage",
2223
"tdd": "jest --watch",
2324
"build:pick": "cherry-pick --name=@restart/hooks --cwd=lib --input-dir=../src --cjs-dir=cjs --esm-dir=esm",
2425
"build": "rimraf lib && 4c build src && yarn build:pick",
26+
"deploy-docs": "yarn --cwd www build --prefix-paths && gh-pages -d www/public",
2527
"prepublishOnly": "yarn build"
2628
},
2729
"jest": {
@@ -65,6 +67,7 @@
6567
"enzyme": "^3.10.0",
6668
"enzyme-adapter-react-16": "^1.15.1",
6769
"eslint": "^6.7.0",
70+
"gh-pages": "^2.2.0",
6871
"husky": "^4.2.3",
6972
"jest": "^25.1.0",
7073
"lint-staged": "^10.0.8",

src/globals.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ interface ResizeObserverEntry {
5353
}
5454

5555
interface DOMRectReadOnly {
56-
static fromRect(other: DOMRectInit | undefined): DOMRectReadOnly
56+
fromRect(other: DOMRectInit | undefined): DOMRectReadOnly
5757

5858
readonly x: number
5959
readonly y: number
File renamed without changes.

src/useFocusManager.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useCallback, useRef } from 'react'
2-
3-
import useMounted from './useMounted'
42
import useEventCallback from './useEventCallback'
3+
import useMounted from './useMounted'
54

65
export interface FocusManagerOptions {
76
/**
@@ -26,13 +25,17 @@ export interface FocusManagerOptions {
2625
isDisabled: () => boolean
2726
}
2827

28+
export interface FocusController {
29+
onBlur: (event: any) => void
30+
onFocus: (event: any) => void
31+
}
2932
/**
3033
* useFocusManager provides a way to track and manage focus as it moves around
3134
* a container element. An `onChange` is fired when focus enters or leaves the
3235
* element, but not when it moves around inside the element, similar to
3336
* `pointerenter` and `pointerleave` DOM events.
3437
*
35-
* ```ts
38+
* ```tsx
3639
* const [focused, setFocusState] = useState(false)
3740
*
3841
* const { onBlur, onFocus } = useFocusManager({
@@ -49,10 +52,10 @@ export interface FocusManagerOptions {
4952
* </div>
5053
* ```
5154
*
52-
* @param opts Options
53-
* @returns FocusController a set of paired focus and blur event handlers
5455
*/
55-
export default function useFocusManager(opts: FocusManagerOptions) {
56+
export default function useFocusManager(
57+
opts: FocusManagerOptions,
58+
): FocusController {
5659
const isMounted = useMounted()
5760

5861
const lastFocused = useRef<boolean | undefined>()

src/useInterval.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ import useCommittedRef from './useCommittedRef'
44
/**
55
* Creates a `setInterval` that is properly cleaned up when a component unmounted
66
*
7+
* ```tsx
8+
* function Timer() {
9+
* const [timer, setTimer] = useState(0)
10+
* useInterval(() => setTimer(i => i + 1), 1000)
11+
*
12+
* return <span>{timer} seconds past</span>
13+
* }
14+
* ```
15+
*
716
* @param fn an function run on each interval
817
* @param ms The milliseconds duration of the interval
918
*/
@@ -12,22 +21,53 @@ function useInterval(fn: () => void, ms: number): void
1221
/**
1322
* Creates a pausable `setInterval` that is properly cleaned up when a component unmounted
1423
*
24+
* ```tsx
25+
* const [paused, setPaused] = useState(false)
26+
* const [timer, setTimer] = useState(0)
27+
*
28+
* useInterval(() => setTimer(i => i + 1), 1000, paused)
29+
*
30+
* return (
31+
* <span>
32+
* {timer} seconds past
33+
*
34+
* <button onClick={() => setPaused(p => !p)}>{paused ? 'Play' : 'Pause' }</button>
35+
* </span>
36+
* )
37+
* ```
38+
*
1539
* @param fn an function run on each interval
1640
* @param ms The milliseconds duration of the interval
1741
* @param paused Whether or not the interval is currently running
1842
*/
1943
function useInterval(fn: () => void, ms: number, paused: boolean): void
2044

2145
/**
22-
* Creates a pausable `setInterval` that is properly cleaned up when a component unmounted
46+
* Creates a pausable `setInterval` that _fires_ immediately and is
47+
* properly cleaned up when a component unmounted
48+
*
49+
* ```tsx
50+
* const [timer, setTimer] = useState(-1)
51+
* useInterval(() => setTimer(i => i + 1), 1000, false, true)
52+
*
53+
* // will update to 0 on the first effect
54+
* return <span>{timer} seconds past</span>
55+
* ```
2356
*
2457
* @param fn an function run on each interval
2558
* @param ms The milliseconds duration of the interval
2659
* @param paused Whether or not the interval is currently running
2760
* @param runImmediately Whether to run the function immediately on mount or unpause
2861
* rather than waiting for the first interval to elapse
62+
*
63+
2964
*/
30-
function useInterval(fn: () => void, ms: number, paused: boolean, runImmediately: boolean): void
65+
function useInterval(
66+
fn: () => void,
67+
ms: number,
68+
paused: boolean,
69+
runImmediately: boolean,
70+
): void
3171

3272
function useInterval(
3373
fn: () => void,

src/useSet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class ObservableSet<V> extends Set<V> {
4949
*
5050
* @param init initial Set values
5151
*/
52-
function useSet<V>(init?: Iterable<V>) {
52+
function useSet<V>(init?: Iterable<V>): ObservableSet<V> {
5353
const forceUpdate = useForceUpdate()
5454
return useStableMemo(() => new ObservableSet<V>(forceUpdate, init), [])
5555
}

www/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../.babelrc"
3+
}

0 commit comments

Comments
 (0)