![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@wordpress/compose
Advanced tools
The compose
package is a collection of handy Higher Order Components (HOCs) you can use to wrap your WordPress components and provide some basic features like: state, instance id, pure...
The compose
function is an alias to 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:
const compose = ( f, g ) => x
=> f( g( x ) );
Here's a simplified example of compose in use from Gutenberg's PluginSidebar
component:
Using compose:
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:
const applyWithSelect = withSelect( ( select, ownProps ) => {
return doSomething( select, ownProps);
} );
const applyWithDispatch = withDispatch( ( dispatch, ownProps ) => {
return doSomethingElse( dispatch, ownProps );
} );
export default withPluginContext(
applyWithSelect(
applyWithDispatch(
PluginSidebarMoreMenuItem
)
)
);
Install the module
npm install @wordpress/compose --save
This package assumes that your code will run in an ES2015+ environment. If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using core-js or @babel/polyfill will add support for these methods. Learn more about it in Babel docs.
For more details, you can refer to each Higher Order Component's README file. Available components are located here.
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.
Parameters
...Function
: The HOC functions to invoke.Returns
Function
: Returns the new composite function.
Given a function mapping a component to an enhanced component and modifier name, returns the enhanced component augmented with a generated displayName.
Parameters
Function
: Function mapping component to enhanced component.string
: Seed name from which to generated display name.Returns
WPComponent
: Component class with generated display name assigned.
Higher-order component creator, creating a new component which renders if the given condition is satisfied or with the given optional prop name.
Parameters
Function
: Function to test condition.Returns
Function
: Higher-order component.
Given a component returns the enhanced component augmented with a component only rerendering when its props/state change
Parameters
Function
: Function mapping component to enhanced component.string
: Seed name from which to generated display name.Returns
WPComponent
: Component class with generated display name assigned.
Undocumented declaration.
A Higher Order Component used to be provide a unique instance ID by component.
Parameters
WPElement
: The wrapped component.Returns
Component
: Component with an instanceId prop.
A higher-order component used to provide and manage delayed function calls that ought to be bound to a component's lifecycle.
Parameters
Component
: Component requiring setTimeoutReturns
Component
: Wrapped component.
A Higher Order Component used to provide and manage internal component state via props.
Parameters
?Object
: Optional initial state of the component.Returns
Component
: Wrapped component.
FAQs
WordPress higher-order components (HOCs).
The npm package @wordpress/compose receives a total of 79,769 weekly downloads. As such, @wordpress/compose popularity was classified as popular.
We found that @wordpress/compose demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 23 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.