Skip to content

Commit 91483cd

Browse files
anomiexmatticbot
authored andcommitted
Cleanup lodash omit function (#44285)
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@c4dc159
1 parent 659320f commit 91483cd

4 files changed

Lines changed: 4 additions & 4 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('jetpack-connection', 'jetpack-script-data', 'lodash', 'moment', 'react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-blob', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-keycodes', 'wp-plugins', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => 'cdba801d40f083c89d4a');
1+
<?php return array('dependencies' => array('jetpack-connection', 'jetpack-script-data', 'lodash', 'moment', 'react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-blob', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-keycodes', 'wp-plugins', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => 'e11fbf4a44038fae2217');

0 commit comments

Comments
 (0)