Skip to content
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 _.isObjectLike() #41701

Merged
merged 1 commit into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ module.exports = {
'isArray',
'isFinite',
'isFunction',
'isObjectLike',
'isUndefined',
'memoize',
'negate',
Expand Down
6 changes: 4 additions & 2 deletions packages/blocks/src/api/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
every,
castArray,
some,
isObjectLike,
filter,
first,
flatMap,
Expand Down Expand Up @@ -541,7 +540,10 @@ export function switchToBlockType( blocks, name ) {

// Ensure that the transformation function returned an object or an array
// of objects.
if ( ! isObjectLike( transformationResults ) ) {
if (
transformationResults === null ||
typeof transformationResults !== 'object'
) {
return null;
}

Expand Down
7 changes: 1 addition & 6 deletions packages/core-data/src/utils/with-weak-map-cache.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { isObjectLike } from 'lodash';

/**
* Given a function, returns an enhanced function which caches the result and
* tracks in WeakMap. The result is only cached if the original function is
Expand All @@ -25,7 +20,7 @@ function withWeakMapCache( fn ) {
// Can reach here if key is not valid for WeakMap, since `has`
// will return false for invalid key. Since `set` will throw,
// ensure that key is valid before setting into cache.
if ( isObjectLike( key ) ) {
if ( key !== null && typeof key === 'object' ) {
cache.set( key, value );
}
}
Expand Down