-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lodash: Remove completely from @wordpress/viewport
package
#44572
Changes from 7 commits
93ce168
7f17ee9
02472db
1ded29d
61472b3
42b23d1
df97e27
92e074e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { mapValues } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
|
@@ -27,24 +22,28 @@ import { store } from './store'; | |
* | ||
* ```jsx | ||
* function MyComponent( { isMobile } ) { | ||
* return ( | ||
* <div>Currently: { isMobile ? 'Mobile' : 'Not Mobile' }</div> | ||
* ); | ||
* return ( | ||
* <div>Currently: { isMobile ? 'Mobile' : 'Not Mobile' }</div> | ||
* ); | ||
* } | ||
* | ||
* MyComponent = withViewportMatch( { isMobile: '< small' } )( MyComponent ); | ||
* ``` | ||
* | ||
* @return {Function} Higher-order component. | ||
*/ | ||
const withViewportMatch = ( queries ) => | ||
createHigherOrderComponent( | ||
const withViewportMatch = ( queries ) => { | ||
const queryEntries = Object.entries( queries ); | ||
return createHigherOrderComponent( | ||
withSelect( ( select ) => { | ||
return mapValues( queries, ( query ) => { | ||
return select( store ).isViewportMatch( query ); | ||
} ); | ||
return Object.fromEntries( | ||
queryEntries.map( ( [ key, query ] ) => { | ||
return [ key, select( store ).isViewportMatch( query ) ]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'm leaning towards keeping it as-is. Do you see any potential big performance improvements from that change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really, it's just a double map lookup, equivalent to |
||
} ) | ||
); | ||
} ), | ||
'withViewportMatch' | ||
); | ||
}; | ||
|
||
export default withViewportMatch; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a missing
Object.fromEntries
here. ThesetIsMatching
action expects an object.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find. Would have been useful to have a test to catch this.
Addressed in 92e074e