Skip to content

Commit

Permalink
Optimize exports of the wp/compose package (#17945)
Browse files Browse the repository at this point in the history
Adds `sideEffects:false` to `package.json` so that unused exports can be optimized away
by the bundler.

Moves the `compose` definition (i.e., reexport from Lodash) to its own module, so that
we don't pull in Lodash just by importing something from `@wordpress/compose`. After this
patch, one needs to import `compose` explicitly to trigger the Lodash import.
  • Loading branch information
jsnajdr authored and hypest committed Nov 4, 2019
1 parent 7017152 commit 30d3e98
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/compose/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"main": "build/index.js",
"module": "build-module/index.js",
"react-native": "src/index",
"sideEffects": false,
"dependencies": {
"@babel/runtime": "^7.4.4",
"@wordpress/element": "file:../element",
Expand Down
14 changes: 14 additions & 0 deletions packages/compose/src/higher-order/compose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* External dependencies
*/
import { flowRight as compose } from 'lodash';

/**
* Composes multiple higher-order components into a single higher-order component. Performs right-to-left function
* composition, where each successive invocation is supplied the return value of the previous.
*
* @param {...Function} hocs The HOC functions to invoke.
*
* @return {Function} Returns the new composite function.
*/
export default compose;
16 changes: 2 additions & 14 deletions packages/compose/src/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
/**
* External dependencies
*/
import { flowRight } from 'lodash';

// Utils
export { default as createHigherOrderComponent } from './utils/create-higher-order-component';

/**
* Composes multiple higher-order components into a single higher-order component. Performs right-to-left function
* composition, where each successive invocation is supplied the return value of the previous.
*
* @param {...Function} hocs The HOC functions to invoke.
*
* @return {Function} Returns the new composite function.
*/
export { flowRight as compose };
// Compose helper (aliased flowRight from Lodash)
export { default as compose } from './higher-order/compose';

// Higher-order components
export { default as ifCondition } from './higher-order/if-condition';
Expand Down

0 comments on commit 30d3e98

Please sign in to comment.