Skip to content

Commit

Permalink
Lodash: Refactor away from _.isObjectLike()
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Jun 14, 2022
1 parent 69259e9 commit e631f2b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ module.exports = {
'findIndex',
'isArray',
'isFinite',
'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

0 comments on commit e631f2b

Please sign in to comment.