Commit 91483cd
Cleanup lodash
When we have a constant array, `newobj = omit( obj, [ 'key1', 'key2', 'etc' ] )`,
that can easily become `const { key1, key2, etc, ...newobj } = obj`.
If we have a single variable key being omitted, like
`newobj = omit( obj, [ var ] )`, that can similarly become
`const { [ var ]: _, ...newobj } = obj`.
The most complex case is when we have a variable with the keys to omit,
`omit( obj, arr )`. The best transformation for that seems to be
`Object.fromEntries( Object.entries( obj ).filter( ( [ k ] ) => ! arr.includes( k ) ) )`
Which, BTW, is still a lot faster than lodash!
(aside: Technically none of these are equivalent if `obj` has non-own
properties from a prototype, since lodash `omit` will include all those
non-own properties, but I don't think we have any cases where that would
apply).
On the other hand, sometimes we can further simplify the code. For
example, we had a lot of React code like
```
<Something
{ ...omit( this.props, 'className' ) }
className={ clsx( this.props.className, 'foo' ) }
>
```
where the `omit` is unnecessary since the following prop assignment will
override the property anyway.
Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/16269423520
Upstream-Ref: Automattic/jetpack@c4dc159omit function (#44285)1 parent 659320f commit 91483cd
4 files changed
Lines changed: 4 additions & 4 deletions
File tree
- src/build
- jetpack-external-media-editor
- jetpack-external-media-import-page
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
0 commit comments