Skip to content
This repository was archived by the owner on Oct 4, 2023. It is now read-only.

Commit 395d178

Browse files
authored
Merge branch 'master' into patch-1
2 parents 364578f + bb8206c commit 395d178

28 files changed

+80
-122
lines changed

.babelrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"presets": ["react-app"]
2+
"presets": ["@babel/preset-env", "@babel/react"],
3+
"ignore": ["**/__tests__"]
34
}

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
Rehook implements an API similar to [Recompose](https://github.com/acdlite/recompose), but using React Hooks.
66

7-
> Note, React Hooks are in alpha. Refer to the official documentation: [React Hooks](https://reactjs.org/docs/hooks-intro.html)
8-
97
```
108
npm i @synvox/rehook
119
```

package.json

+16-19
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "@synvox/rehook",
33
"public": true,
4-
"version": "0.0.14",
5-
"main": "dist/rehook.js",
6-
"umd:main": "dist/rehook.umd.js",
7-
"source": "src/rehook/index.js",
8-
"types": "dist/rehook.d.ts",
4+
"version": "0.0.16",
5+
"main": "dist/index.js",
96
"devDependencies": {
7+
"@babel/cli": "^7.1.5",
8+
"@babel/preset-env": "^7.1.6",
9+
"@babel/preset-react": "^7.0.0",
1010
"@otris/jsdoc-tsd": "^1.0.4",
11+
"@types/jest": "^24.0.11",
1112
"babel-eslint": "9.0.0",
1213
"enzyme": "^3.7.0",
1314
"enzyme-adapter-react-16": "^1.6.0",
@@ -24,32 +25,28 @@
2425
"eslint-plugin-standard": "^4.0.0",
2526
"husky": "^1.1.3",
2627
"jsdoc": "^3.5.5",
27-
"microbundle": "^0.7.0",
2828
"prettier": "1.14.3",
29-
"react": "^16.7.0-alpha.0",
30-
"react-dom": "^16.7.0-alpha.0",
29+
"react": "^16.8.6",
30+
"react-dom": "^16.8.6",
3131
"react-scripts": "2.1.0",
32-
"rollup": "^0.67.1",
33-
"rollup-plugin-babel": "^4.0.3",
34-
"rollup-plugin-commonjs": "^9.2.0",
35-
"rollup-plugin-node-resolve": "^3.4.0",
36-
"rollup-plugin-replace": "^2.1.0",
37-
"rollup-plugin-uglify": "^6.0.0"
32+
"tsc": "^1.20150623.0"
3833
},
3934
"peerDependencies": {
40-
"react": "^16.7.0-alpha.0",
41-
"react-dom": "^16.7.0-alpha.0"
35+
"react": "^16.8.6",
36+
"react-dom": "^16.8.6"
4237
},
4338
"scripts": {
4439
"start": "react-scripts start",
45-
"build": "react-scripts build",
40+
"build:cra": "react-scripts build",
4641
"test:eslint": "eslint src --fix",
4742
"test:jest": "react-scripts test",
4843
"test": "CI=true npm run test:eslint && CI=true npm run test:jest --findRelatedTests",
4944
"eject": "react-scripts eject",
50-
"build:bundle": "NODE_ENV='production' rollup --config rollup.config.js",
45+
"build": "npm run build:bundle && npm run build:types && npm run build:package",
46+
"build:bundle": "NODE_ENV='production' babel -s -d ./dist/ ./src/rehook",
47+
"build:package": "cp ./README.md dist/README.md && cp ./package.json dist/package.json",
5148
"build:types": "jsdoc -t node_modules/@otris/jsdoc-tsd -r ./src/rehook -d dist/rehook.d.ts",
52-
"prepublish": "npm run build:bundle && npm run build:types"
49+
"pub": "npm run build && npm publish"
5350
},
5451
"browserslist": [
5552
">0.2%",

src/app.js

-36
This file was deleted.

src/index.js

-5
This file was deleted.

src/rehook/__tests__/with-props-on-change-test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import testUtil from '../test-utils'
44
import pipe from '../pipe'
55
import withState from '../with-state'
66
import withPropsOnChange from '../with-props-on-change'
7+
import { act } from 'react-dom/test-utils'
78

89
test('maps props using fn true', () => {
910
let called = 0
@@ -26,7 +27,7 @@ test('maps props using fn true', () => {
2627
expect(getProps().a).toBe(true)
2728
expect(getProps().b).toBe(0)
2829
expect(called).toBe(1)
29-
getProps().setB(1)
30+
act(() => getProps().setB(1))
3031
expect(called).toBe(2)
3132
expect(getProps().a).toBe(true)
3233
expect(getProps().c).toBe(1)
@@ -53,7 +54,7 @@ test('maps props using fn false', () => {
5354
expect(getProps().a).toBe(true)
5455
expect(getProps().b).toBe(0)
5556
expect(called).toBe(1)
56-
getProps().setB(1)
57+
act(() => getProps().setB(1))
5758
expect(called).toBe(1)
5859
expect(getProps().a).toBe(true)
5960
expect(getProps().c).toBe(0)
@@ -77,7 +78,7 @@ test('maps props using keys', () => {
7778
expect(getProps().a).toBe(true)
7879
expect(getProps().b).toBe(0)
7980
expect(called).toBe(1)
80-
getProps().setB(1)
81+
act(() => getProps().setB(1))
8182
expect(called).toBe(2)
8283
expect(getProps().a).toBe(true)
8384
expect(getProps().b).toBe(1)

src/rehook/__tests__/with-reducer-test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import testUtil from '../test-utils'
44
import withReducer from '../with-reducer'
5+
import { act } from 'react-dom/test-utils'
56

67
test('with state handlers', () => {
78
const getProps = testUtil(
@@ -22,7 +23,7 @@ test('with state handlers', () => {
2223
)
2324

2425
expect(getProps().state).toEqual({ count: 0 })
25-
getProps().dispatch({ type: 'INCREMENT' })
26+
act(() => getProps().dispatch({ type: 'INCREMENT' }))
2627
expect(getProps().state).toEqual({ count: 1 })
2728
})
2829

@@ -45,6 +46,6 @@ test('with state handlers memo', () => {
4546
)
4647

4748
expect(getProps().state).toEqual({ count: 0 })
48-
getProps().dispatch({ type: 'INCREMENT' })
49+
act(() => getProps().dispatch({ type: 'INCREMENT' }))
4950
expect(getProps().state).toEqual({ count: 1 })
5051
})

src/rehook/__tests__/with-state-handlers-test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import testUtil from '../test-utils'
44
import withStateHandlers from '../with-state-handlers'
5+
import { act } from 'react-dom/test-utils'
56

67
test('with state handlers', () => {
78
const getProps = testUtil(
@@ -14,7 +15,7 @@ test('with state handlers', () => {
1415
{}
1516
)
1617

17-
getProps().handle({ b: true })
18+
act(() => getProps().handle({ b: true }))
1819
expect(getProps().b).toEqual(true)
1920
})
2021

@@ -29,7 +30,7 @@ test('with state handlers calling undefined', () => {
2930
{}
3031
)
3132

32-
getProps().handle()
33+
act(() => getProps().handle())
3334
expect(getProps().b).toEqual(false)
3435
})
3536

@@ -41,6 +42,6 @@ test('with state handlers memo', () => {
4142
{}
4243
)
4344

44-
getProps().handle({ b: true })
45+
act(() => getProps().handle({ b: true }))
4546
expect(getProps().b).toEqual(true)
4647
})

src/rehook/__tests__/with-state-test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
import testUtil from '../test-utils'
44
import withState from '../with-state'
5+
import { act } from 'react-dom/test-utils'
56

67
test('with state', () => {
78
const getProps = testUtil(withState('state', 'setState', 0))
89

910
expect(getProps().state).toEqual(0)
10-
getProps().setState(1)
11+
act(() => getProps().setState(1))
1112
expect(getProps().state).toEqual(1)
1213
})
1314
test('with state function', () => {
@@ -20,7 +21,7 @@ test('with state function', () => {
2021
)
2122

2223
expect(getProps().state).toEqual(0)
23-
getProps().setState(1)
24+
act(() => getProps().setState(1))
2425
expect(getProps().state).toEqual(1)
2526
expect(called).toEqual(1)
2627
})

src/rehook/branch.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import React from 'react'
2-
// @ts-ignore
3-
const { useMemo } = React
4-
1+
// @ts-check
2+
import { useMemo } from 'react'
53
// Note, branching disobeys one of the hook rules because
64
// it wraps hooks in a condition. For this reason, the branch
75
// is cached and kept the same regardless of updates.
86

97
/**
10-
*
118
* @param {Function} condition
129
* @param {Function} left
1310
* @param {Function} right

src/rehook/catch-render.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
// @ts-check
12
import React from 'react'
23

34
/**
45
* @param {Function} component
5-
* @returns {Object}
6+
* @returns {object}
67
*/
78
const catchRender = component => {
89
const newComponent = (props = {}) => {
@@ -19,6 +20,7 @@ const catchRender = component => {
1920
}
2021

2122
newComponent.displayName =
23+
// @ts-ignore
2224
component.displayName || component.name || 'Component'
2325

2426
return newComponent

src/rehook/default-props.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
// @ts-check
12
/**
2-
* @param {Object} defaultProps
3-
* @returns {Object}
3+
* @param {object} defaultProps
4+
* @returns {object}
45
*/
56
const defaultProps = defaultProps => (props = {}) => ({
67
...defaultProps,

src/rehook/flatten-prop.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
// @ts-check
12
/**
23
* @param {string|symbol} propName
3-
* @returns {Object}
4+
* @returns {object}
45
*/
56
const flattenProp = propName => (props = {}) => ({
67
...props,

src/rehook/lifecycle.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import React from 'react'
2-
// @ts-ignore
3-
const { useEffect, useRef, useState } = React
1+
// @ts-check
2+
import { useEffect, useRef, useState } from 'react'
43

54
function usePrevious(value) {
6-
const ref = useRef()
5+
const ref = useRef(null)
76

87
useEffect(() => {
98
ref.current = value
@@ -13,8 +12,8 @@ function usePrevious(value) {
1312
}
1413

1514
/**
16-
* @param {Object} spec
17-
* @returns {Object}
15+
* @param {object} spec
16+
* @returns {object}
1817
*/
1918
const lifecycle = spec => (props = {}) => {
2019
const [state, setStateRaw] = useState({})

src/rehook/map-props.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
// @ts-check
12
/**
23
* @param {Function} fn
3-
* @returns {Object}
4+
* @returns {object}
45
*/
56
const mapProps = fn => (props = {}) => fn(props)
67

src/rehook/namespace.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
// @ts-check
12
/**
23
* @param {string|symbol} propName
34
* @param {Function} enhance
4-
* @returns {Object}
5+
* @returns {object}
56
*/
67
const namespace = (propName, enhance) => (props = {}) => ({
78
...props,

src/rehook/pipe.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
// @ts-check
12
/**
23
* @param {...Function[]} fns
3-
* @returns {Object}
4+
* @returns {object}
45
*/
56
const pipe = (...fns) => (props = {}) => fns.reduce((v, f) => f(v), props)
67

src/rehook/rename-prop.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
// @ts-check
12
/**
23
* @param {string|symbol} a
34
* @param {string|symbol} b
4-
* @returns {Object}
5+
* @returns {object}
56
*/
67
const renameProp = (a, b) => ({ [a]: prop, ...props } = {}) => ({
78
...props,

src/rehook/rename-props.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
// @ts-check
12
/**
2-
* @param {Object} propMap
3-
* @returns {Object}
3+
* @param {object} propMap
4+
* @returns {object}
45
*/
56
const renameProps = propMap => (props = {}) => ({
67
// Remove renamed props

src/rehook/render-component.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
// @ts-check
12
/**
23
* @param {any} comp
3-
* @returns {Object}
4+
* @returns {object}
45
*/
56
const renderComponent = comp => (props = {}) => {
67
throw comp(props)

src/rehook/render-nothing.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
// @ts-check
12
/**
2-
* @returns {Object}
3+
* @returns {object}
34
*/
45
const renderNothing = (/* props */) => {
56
// eslint-disable-next-line
6-
throw null;
7+
throw null
78
}
89

910
export default renderNothing

src/rehook/test-utils.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-check
12
import React from 'react'
23
import { mount } from 'enzyme'
34

0 commit comments

Comments
 (0)