@wordpress/compose
Advanced tools
Comparing version 3.0.1 to 3.1.0
### WordPress - Web publishing software | ||
Copyright 2011-2018 by the contributors | ||
Copyright 2011-2019 by the contributors | ||
@@ -5,0 +5,0 @@ This program is free software; you can redistribute it and/or modify |
{ | ||
"name": "@wordpress/compose", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "WordPress higher-order components (HOCs).", | ||
@@ -15,3 +15,4 @@ "author": "The WordPress Contributors", | ||
"type": "git", | ||
"url": "https://github.com/WordPress/gutenberg.git" | ||
"url": "https://github.com/WordPress/gutenberg.git", | ||
"directory": "packages/compose" | ||
}, | ||
@@ -25,6 +26,6 @@ "bugs": { | ||
"dependencies": { | ||
"@babel/runtime": "^7.0.0", | ||
"@wordpress/element": "^2.1.9", | ||
"@wordpress/is-shallow-equal": "^1.1.5", | ||
"lodash": "^4.17.10" | ||
"@babel/runtime": "^7.3.1", | ||
"@wordpress/element": "^2.2.0", | ||
"@wordpress/is-shallow-equal": "^1.2.0", | ||
"lodash": "^4.17.11" | ||
}, | ||
@@ -34,3 +35,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "c59ef56fe16bdcc1fffd70b6e8a2fda4bf9c28fe" | ||
"gitHead": "80d228669adadb8dfcd24b8421517fed3be2d474" | ||
} |
@@ -5,2 +5,49 @@ # Compose | ||
The `compose` function is an alias to [flowRight](https://lodash.com/docs/#flowRight) from Lodash. It comes from functional programming, and allows you to compose any number of functions. You might also think of this as layering functions; `compose` will execute the last function first, then sequentially move back through the previous functions passing the result of each function upward. | ||
An example that illustrates it for two functions: | ||
```js | ||
const compose = ( f, g ) => x | ||
=> f( g( x ) ); | ||
``` | ||
Here's a simplified example of **compose** in use from Gutenberg's [`PluginSidebar` component](https://github.com/WordPress/gutenberg/blob/master/packages/edit-post/src/components/sidebar/plugin-sidebar/index.js): | ||
Using compose: | ||
```js | ||
const applyWithSelect = withSelect( ( select, ownProps ) => { | ||
return doSomething( select, ownProps); | ||
} ); | ||
const applyWithDispatch = withDispatch( ( dispatch, ownProps ) => { | ||
return doSomethingElse( dispatch, ownProps ); | ||
} ); | ||
export default compose( | ||
withPluginContext, | ||
applyWithSelect, | ||
applyWithDispatch, | ||
)( PluginSidebarMoreMenuItem ); | ||
``` | ||
Without `compose`, the code would look like this: | ||
```js | ||
const applyWithSelect = withSelect( ( select, ownProps ) => { | ||
return doSomething( select, ownProps); | ||
} ); | ||
const applyWithDispatch = withDispatch( ( dispatch, ownProps ) => { | ||
return doSomethingElse( dispatch, ownProps ); | ||
} ); | ||
export default withPluginContext( | ||
applyWithSelect( | ||
applyWithDispatch( | ||
PluginSidebarMoreMenuItem | ||
) | ||
) | ||
); | ||
## Installation | ||
@@ -18,2 +65,4 @@ | ||
An example using the HOC `withInstanceId` from the compose package: | ||
```js | ||
@@ -29,4 +78,4 @@ import { withInstanceId } from '@wordpress/compose'; | ||
Refer to each Higher Order Component's README file for more details. | ||
For more details, you can refer to each Higher Order Component's README file. [Available components are located here.](https://github.com/WordPress/gutenberg/tree/master/packages/compose/src) | ||
<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p> |
@@ -7,3 +7,3 @@ /** | ||
/** | ||
* External dependencies | ||
* WordPress dependencies | ||
*/ | ||
@@ -10,0 +10,0 @@ import { Component } from '@wordpress/element'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
126478
79
Updated@babel/runtime@^7.3.1
Updated@wordpress/element@^2.2.0
Updatedlodash@^4.17.11