From e631f2b51f2d96d3c221bad86613b1eca1e1154e Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Mon, 13 Jun 2022 20:07:13 +0300 Subject: [PATCH] Lodash: Refactor away from _.isObjectLike() --- .eslintrc.js | 1 + packages/blocks/src/api/factory.js | 6 ++++-- packages/core-data/src/utils/with-weak-map-cache.js | 7 +------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 6beaf2e881b997..457d7db66271aa 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -85,6 +85,7 @@ module.exports = { 'findIndex', 'isArray', 'isFinite', + 'isObjectLike', 'isUndefined', 'memoize', 'negate', diff --git a/packages/blocks/src/api/factory.js b/packages/blocks/src/api/factory.js index ba0faf7eeb276e..4eaf2124db26f9 100644 --- a/packages/blocks/src/api/factory.js +++ b/packages/blocks/src/api/factory.js @@ -6,7 +6,6 @@ import { every, castArray, some, - isObjectLike, filter, first, flatMap, @@ -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; } diff --git a/packages/core-data/src/utils/with-weak-map-cache.js b/packages/core-data/src/utils/with-weak-map-cache.js index 577fcc53e73004..4f9b4e5af35f7a 100644 --- a/packages/core-data/src/utils/with-weak-map-cache.js +++ b/packages/core-data/src/utils/with-weak-map-cache.js @@ -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 @@ -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 ); } }