diff --git a/package-lock.json b/package-lock.json index 50c84942b40138..e0b8e5e63b330a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17588,7 +17588,6 @@ "equivalent-key-map": "^0.2.2", "is-plain-object": "^5.0.0", "is-promise": "^4.0.0", - "lodash": "^4.17.21", "redux": "^4.1.2", "turbo-combine-reducers": "^1.0.2", "use-memo-one": "^1.1.1" @@ -29592,7 +29591,7 @@ "co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", - "integrity": "sha512-QVb0dM5HvG+uaxitm8wONl7jltx8dqhfU33DcqtOZcLSVIKSDDLDi7+0LbAKiyI8hD9u42m2YxXSkMGWThaecQ==", + "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=", "dev": true }, "code-point-at": { @@ -43686,7 +43685,7 @@ "lodash.isequal": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", - "integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==" + "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" }, "lodash.ismatch": { "version": "4.4.0", diff --git a/packages/data/README.md b/packages/data/README.md index 58d6a6976898a6..60122046dc9119 100644 --- a/packages/data/README.md +++ b/packages/data/README.md @@ -164,7 +164,6 @@ Integrating an existing redux store with its own reducers, store enhancers and m _Example:_ ```js -import { mapValues } from 'lodash'; import { register } from '@wordpress/data'; import existingSelectors from './existing-app/selectors'; import existingActions from './existing-app/actions'; @@ -172,6 +171,15 @@ import createStore from './existing-app/store'; const reduxStore = createStore(); +const mapValues = ( obj, callback ) => + Object.entries( obj ).reduce( + ( acc, [ key, value ] ) => ( { + ...acc, + [ key ]: callback( value ), + } ), + {} + ); + const boundSelectors = mapValues( existingSelectors, ( selector ) => diff --git a/packages/data/package.json b/packages/data/package.json index 1680f2916b5af4..48fef3e9f46fd8 100644 --- a/packages/data/package.json +++ b/packages/data/package.json @@ -40,7 +40,6 @@ "equivalent-key-map": "^0.2.2", "is-plain-object": "^5.0.0", "is-promise": "^4.0.0", - "lodash": "^4.17.21", "redux": "^4.1.2", "turbo-combine-reducers": "^1.0.2", "use-memo-one": "^1.1.1" diff --git a/packages/data/src/redux-store/index.js b/packages/data/src/redux-store/index.js index 0ecaf2b941c46e..cc716a7a342bdb 100644 --- a/packages/data/src/redux-store/index.js +++ b/packages/data/src/redux-store/index.js @@ -2,7 +2,6 @@ * External dependencies */ import { createStore, applyMiddleware } from 'redux'; -import { get, mapValues } from 'lodash'; import combineReducers from 'turbo-combine-reducers'; import EquivalentKeyMap from 'equivalent-key-map'; @@ -45,6 +44,23 @@ const trimUndefinedValues = ( array ) => { return result; }; +/** + * Creates a new object with the same keys, but with `callback()` called as + * a transformer function on each of the values. + * + * @param {Object} obj The object to transform. + * @param {Function} callback The function to transform each object value. + * @return {Array} Transformed object. + */ +const mapValues = ( obj, callback ) => + Object.entries( obj ?? {} ).reduce( + ( acc, [ key, value ] ) => ( { + ...acc, + [ key ]: callback( value, key ), + } ), + {} + ); + // Convert Map objects to plain objects const mapToObject = ( key, state ) => { if ( state instanceof Map ) { @@ -608,7 +624,7 @@ function mapResolvers( resolvers, selectors, store, resolversCache ) { * @param {Array} args Selector Arguments. */ async function fulfillResolver( store, resolvers, selectorName, ...args ) { - const resolver = get( resolvers, [ selectorName ] ); + const resolver = resolvers[ selectorName ]; if ( ! resolver ) { return; }