Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Replaces getLatestPosts usage (wp.api.collections.Posts wrapper) with withAPIData HoC #4046
This PR replaces getLatestPosts usage (wp.api.collections.Posts wrapper) with withAPIData HoC in latestPosts. It makes the block more inline with the rest of the codebase.
How Has This Been Tested?
Use the latest posts block to try to change the options in the query panel and verify things work as expected.
Types of changes
Removed getLatestPosts definition and related logic in latest posts block. In the render function only the first line was changed "const latestPosts = this.props.latestPosts.data;", the rest of the function was not changed, although it appears in diff because it was moved to another file.
We can probably use an equivalent of node.js querystring, like https://github.com/sindresorhus/query-string. As we were just needing a serialization (when I started it looked very simple) and I was not predicting the need for the other features like parsing, I thought adding a utils function would be a better option instead of adding a new dependency. But I can try using an external version.
The Node built-in modules are stubbed by Webpack, so we shouldn't need to explicitly add a dependency for it.† I think in cases where we can leverage an existing solid Node / npm solution, we shouldn't go out of our way to reinvent the wheel unless we can benefit from a simplified, WordPress-specific offering.
† That said, the default stubbed
There's a warning when toggling "Display post date", but I'm also seeing it on master, so not likely introduced by these changes:
react-dom.d3299c8d.js:894 Warning: A component is changing an uncontrolled input of type checkbox to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: https://fb.me/react-controlled-components