Skip to content

Commit

Permalink
Update to 0.27.0 (#10)
Browse files Browse the repository at this point in the history
* Add CHANGELOG.md

* add lifecycle example in docs

* filter packages by the existence of a package.json file (acdlite#575)

* use static class properties to convert toClass implicit return arrow

* Adding an optional callback argument to the `dispatch` method provided by `withReducer`

* Fix babel-plugin-lodash name on readme (acdlite#606)

* Add a debugging section in README

* Fix a typo in README

* Update docs & readme

* babel-preset-es2015 -> babel-preset-env

* change rest element to be the last in restructuring

* Pass blacklist argument to hoist-non-react-statics using hoistStatics

* Add blacklist docs for hoistStatics (acdlite#635)

* Refactor rollup config (acdlite#645)

- move all bundles into dist folder
- add size snapshot
- remove treeshake test

* Update dependencies before changes according to React 16.3+ (acdlite#646)

* New lifecycles support (acdlite#647)

* Remove cache from withHandlers

* Update createSink

* Update withPropsOnChange

* remove memoize as useless

* Simplify code

* Include flow types into library (acdlite#649)

* Fix types for modern flow

* Move flow declarations and test into recompose

* Fix docs

* Remove errors

* Add yarn-error to gitignore

* Append flow 2 test

* Update release to support flow types

* Remove unneeded command

* recompose v0.27.0

* chore: update yarn.lock

* chore: update yarn.lock

* fix: fix scripts

* fix: remove flow command in test
  • Loading branch information
neighborhood999 authored Apr 22, 2018
1 parent e50be07 commit 0a3819d
Show file tree
Hide file tree
Showing 55 changed files with 3,258 additions and 1,514 deletions.
11 changes: 6 additions & 5 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
{
"plugins": [
["transform-class-properties", { "loose": true }],
"transform-object-rest-spread"
"transform-object-rest-spread",
"transform-runtime"
],
"presets": [
["es2015", { "loose": true, "modules": false }],
["env", { "loose": true, "modules": false }],
"react"
],
"env": {
"cjs": {
"plugins": [
["transform-es2015-modules-commonjs", { "loose": true }]
"transform-es2015-modules-commonjs"
]
},
"rollup": {
"test": {
"plugins": [
"external-helpers"
"transform-es2015-modules-commonjs"
]
}
}
Expand Down
4 changes: 2 additions & 2 deletions types/flow-typed/.flowconfig → .flowconfig
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[ignore]
<PROJECT_ROOT>/types/.*

[include]

[libs]
../flow-typed/recompose_v0.24.x/flow_v0.55.x-/recompose_v0.24.x.js

[options]
suppress_comment=\\(.\\|\n\\)*\\$ExpectError

[lints]
[lints]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ release
lib
coverage
.vscode
yarn-error.log
_book
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
package.json
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
semi: false
singleQuote: true
trailingComma: es5
21 changes: 21 additions & 0 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"lib/packages/recompose/dist/Recompose.umd.js": {
"bundled": 78789,
"minified": 29082,
"gzipped": 9356
},
"lib/packages/recompose/dist/Recompose.min.js": {
"bundled": 75283,
"minified": 27833,
"gzipped": 8952
},
"lib/packages/recompose/dist/Recompose.esm.js": {
"bundled": 31265,
"minified": 15642,
"gzipped": 3464,
"treeshaked": {
"rollup": 569,
"webpack": 1797
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const ClassComponent = toClass(FunctionComponent)

## 支援 Flow

[閱讀文件](types)
[閱讀文件](docs/flow.md)

## Translation

Expand Down
26 changes: 25 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,21 @@ const PostsListWithData = lifecycle({
})(PostsList);
```
Example:
```js
const PostsList = ({ posts }) => (
<ul>{posts.map(p => <li>{p.title}</li>)}</ul>
)

const PostsListWithData = lifecycle({
componentDidMount() {
fetchPosts().then(posts => {
this.setState({ posts });
})
}
})(PostsList);
```
### `toClass()`
```js
Expand Down Expand Up @@ -711,13 +726,22 @@ const ABC = nest(A, B, C)
### `hoistStatics()`
```js
hoistStatics(hoc: HigherOrderComponent): HigherOrderComponent
hoistStatics(
hoc: HigherOrderComponent,
blacklist: Object
): HigherOrderComponent
```
增強一個 higher-order component,以便在使用時它複製非 react static 屬性從 base component 到新的 component。這對於當使用 Recompose 和像是 Relay 之類的 library 的時候非常有用。
注意這只 hoist _非 react_ 的 static 屬性。以下的 static 屬性將不會被 hoist:`childContextTypes``contextTypes``defaultProps``displayName``getDefaultProps``mixins``propTypes``type`。以下原生的 static 方法也會被忽略:`name``length``prototype``caller``arguments``arity`
You can exclude more static properties by passing them as `blacklist` object:
```js
hoistStatics(EnhancedComponent, { foo: true })(BaseComponent) // Exclude `foo`
```
## Observable utilities
事實證明大部分的 React Component API 可以用 observable 的方式來表示:
Expand Down
92 changes: 92 additions & 0 deletions docs/flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Flow support for recompose

## How it works

In most cases all you need is to declare a props type of enhanced Component.
Flow will infer all other types you need.

Example:

```javascript
import type { HOC } from 'recompose';

type EnhancedComponentProps = {
text?: string,
};

const baseComponent = ({ text }) => <div>{text}</div>;

const enhance:HOC<*, EnhancedComponentProps> = compose(
defaultProps({
text: 'world',
}),
withProps(({ text }) => ({
text: `Hello ${text}`
}))
);

export default enhance(baseComponent);

```

See it in action.

![recompose-flow](https://user-images.githubusercontent.com/5077042/28116959-0c96ae2c-6714-11e7-930e-b1454c629908.gif)

## How to start

The easiest way is to start from example.

Look at [this](http://grader-meets-16837.netlify.com/) app [source](../types/flow-example)


## Support

Type definitions of recompose HOCs are splitted into 2 parts.

### Part 1 - HOCs with good flow support

In most cases you can use them without big issues.
Type inference and errors detection works near well.

These HOCs are: *defaultProps, mapProps, withProps, withStateHandlers, withHandlers, pure, onlyUpdateForKeys, shouldUpdate, renderNothing, renderComponent, branch, withPropsOnChange, onlyUpdateForPropTypes, toClass, withContext, getContext, setStatic, setPropTypes, setDisplayName*

#### Known issues for "good" HOCs

see `test_mapProps.js` - inference work but type errors are not detected in hocs

### Part 2 - other HOCs

To use these HOCs - you need to provide type information (no automatic type inference).
You must be a good voodoo dancer.

See `test_voodoo.js` for the idea.

Some recomendations:

- *flattenProp,renameProp, renameProps* can easily be replaced with _withProps_
- *withReducer, withState* -> use _withStateHandlers_ instead
- _lifecycle_ -> you don't need recompose if you need a _lifecycle_, just use React class instead
- _mapPropsStream_ -> see `test_mapPropsStream.js`

#### Known issues for above HOCs

See `test_voodoo.js`, `test_mapPropsStream.js`

### Utils

*getDisplayName, wrapDisplayName, shallowEqual,isClassComponent, createSink, componentFromProp, nest, hoistStatics.*

### Articles

[Typing Higher-order Components in Recompose With Flow](https://medium.com/flow-type/flow-support-in-recompose-1b76f58f4cfc)

### Faq

Why to use existential type with `HOC<*, Blbla>` isn't it possible to avoid this?

*I tried to use type alias but haven't found how to make it work.*

## Thanks

Big thanks to [@gcanti](https://github.com/gcanti) for his work on PR [#241](https://github.com/acdlite/recompose/pull/241), it was nice and clear base for current definitions.
40 changes: 21 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"license": "MIT",
"scripts": {
"lint": "eslint scripts src",
"build-recompose": "cross-env BABEL_ENV=rollup rollup --config scripts/rollup.config.js --environment BUILD:es,PACKAGE_NAME:recompose",
"test": "yarn run build-recompose && cross-env BABEL_ENV=cjs jest --coverage",
"build:recompose": "cross-env PACKAGE_NAME=recompose rollup --config scripts/rollup.config.js",
"test": "jest",
"test:watch": "cross-env BABEL_ENV=cjs jest --watch",
"release": "node scripts/release.js",
"postinstall": "node scripts/installNestedPackageDeps.js",
Expand Down Expand Up @@ -44,49 +44,50 @@
"babel-cli": "^6.24.1",
"babel-core": "^6.5.2",
"babel-eslint": "^6.0.4",
"babel-jest": "^20.0.3",
"babel-jest": "^22.4.3",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-transform-class-properties": "^6.8.0",
"babel-plugin-transform-object-rest-spread": "^6.8.0",
"babel-preset-es2015": "^6.24.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"baconjs": "^0.7.84",
"chalk": "^1.1.1",
"change-case": "^2.3.1",
"codecov": "^1.0.1",
"create-react-class": "^15.5.0",
"cross-env": "^4.0.0",
"enzyme": "^2.2.0",
"enzyme": "^3.3.0",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-config-prettier": "^1.7.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-prettier": "^2.0.1",
"eslint-plugin-react": "^6.10.3",
"flow-bin": "^0.70.0",
"flyd": "^0.2.4",
"gitbook-cli": "^2.3.0",
"husky": "^0.13.3",
"jest": "^20.0.4",
"jest": "^22.4.3",
"kefir": "^3.2.3",
"lint-staged": "^3.4.0",
"most": "^1.0.2",
"prettier": "^1.2.2",
"prop-types": "^15.5.0",
"react": "^15.0.0",
"react-addons-test-utils": "^15.0.0",
"react-dom": "^15.0.0",
"react-test-renderer": "^15.5.4",
"prop-types": "^15.6.1",
"react": "^16.3.1",
"react-dom": "^16.3.1",
"readline-sync": "^1.2.21",
"rimraf": "^2.6.1",
"rollup": "^0.41.6",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-replace": "^1.1.1",
"rollup-plugin-uglify": "^1.0.1",
"rollup": "^0.57.1",
"rollup-plugin-babel": "^3.0.3",
"rollup-plugin-commonjs": "^9.1.0",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-size-snapshot": "^0.3.0",
"rollup-plugin-uglify": "^3.0.0",
"rx": "^4.1.0",
"rxjs": "^5.0.0-beta.9",
"rxjs": "^5.0.0",
"shelljs": "^0.6.0",
"sinon": "^1.17.1",
"webpack": "^2.4.1",
Expand All @@ -99,6 +100,7 @@
"dependencies": {
"gitbook-plugin-github": "^2.0.0",
"gitbook-plugin-prism": "^2.3.0",
"gitbook-plugin-sharing": "^1.0.2"
"gitbook-plugin-sharing": "^1.0.2",
"enzyme-adapter-react-16": "^1.1.1"
}
}
5 changes: 5 additions & 0 deletions scripts/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
/* eslint-disable */
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000

import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

Enzyme.configure({ adapter: new Adapter() })
25 changes: 12 additions & 13 deletions scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { flowRight: compose } = require('lodash')
const readline = require('readline-sync')
const semver = require('semver')
const glob = require('glob')
const { pascalCase } = require('change-case')

const BIN = './node_modules/.bin'

Expand Down Expand Up @@ -47,6 +48,8 @@ try {
)
}

const libraryName = pascalCase(packageName)

const versionLoc = path.resolve(PACKAGES_SRC_DIR, packageName, 'VERSION')
const version = fs.readFileSync(versionLoc, 'utf8').trim()

Expand Down Expand Up @@ -119,22 +122,18 @@ try {
)

log(`Building ${packageName}...`)
const runRollup = build =>
'cross-env BABEL_ENV=rollup rollup --config scripts/rollup.config.js ' +
`--environment BUILD:${build},PACKAGE_NAME:${packageName}`
if (
exec(
[
runRollup('es'),
runRollup('cjs'),
runRollup('umd'),
runRollup('min'),
].join(' && ')
).code !== 0
) {
const runRollup = () => `yarn build:${packageName}`
if (exec(runRollup()).code !== 0) {
exit(1)
}

log(`Preparing ${libraryName}.cjs.js.flow...`)
cp(
'-f',
path.resolve(sourceDir, 'index.js.flow'),
path.resolve(outDir, 'dist', `${libraryName}.cjs.js.flow`)
)

log(`About to publish ${packageName}@${nextVersion} to npm.`)
if (!readline.keyInYN('Sound good? ')) {
log('OK. Stopping release.')
Expand Down
Loading

0 comments on commit 0a3819d

Please sign in to comment.