-
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: Refactor away from _.set()
in core-data
#48784
Conversation
Size Change: +1.61 kB (0%) Total Size: 1.34 MB
ℹ️ View Unchanged
|
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.
LGTM, left a suggestion. Thanks, @tyxla! 👍
import setNestedValue from '../set-nested-value'; | ||
|
||
describe( 'setNestedValue', () => { | ||
it( 'should return the same object unmodified if path is an empty array', () => { |
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.
We should probably add some tests to ensure that it behaves correctly if input is not an object, e.g. null
or undefined
. I'll leave it to your judgement what "behaves correctly" should mean; lodash
simply does nothing, but throwing an error may be a good alternative as well.
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 point. Happy to alter it to do nothing as well - it's a simple condition. I've done it in 37cf182 where I also added some additional unit tests.
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.
Looks great, thank you!
Flaky tests detected in 37cf182. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4404789928
|
What?
This PR removes Lodash's
_.set()
from the@wordpress/core-data
package.Why?
Lodash is known to unnecessarily inflate the bundle size of packages, and in most cases, it can be replaced with native language functionality. See these for more information and rationale:
@wordpress/api-fetch
package haslodash
as a dependency #39495How?
We're introducing a utility function that serves as a replacement for
_.set()
since this package works with various values and data structures, is very broadly used, and the original_.set()
is used in a couple of places within the package.We're keeping the original logic that mutates the original object and preserving the original array behavior. We're also adding some tests to ensure everything works as expected.
Testing Instructions