diff --git a/lib/Onyx.js b/lib/Onyx.js index 2de92b240..cd5ba9143 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -1,6 +1,5 @@ /* eslint-disable no-continue */ import {deepEqual} from 'fast-equals'; -import lodashGet from 'lodash/get'; import _ from 'underscore'; import * as Logger from './Logger'; import cache from './OnyxCache'; @@ -48,17 +47,13 @@ let defaultKeyStates = {}; const deferredInitTask = createDeferredTask(); /** - * Uses a selector string or function to return a simplified version of sourceData + * Uses a selector function to return a simplified version of sourceData * @param {Mixed} sourceData - * @param {String|Function} selector + * @param {Function} selector Function that takes sourceData and returns a simplified version of it * @param {Object} [withOnyxInstanceState] - * If it's a string, the selector is passed to lodashGet on the sourceData - * If it's a function, it is passed the sourceData and it should return the simplified data * @returns {Mixed} */ -const getSubsetOfData = (sourceData, selector, withOnyxInstanceState) => (_.isFunction(selector) - ? selector(sourceData, withOnyxInstanceState) - : lodashGet(sourceData, selector)); +const getSubsetOfData = (sourceData, selector, withOnyxInstanceState) => selector(sourceData, withOnyxInstanceState); /** * Takes a collection of items (eg. {testKey_1:{a:'a'}, testKey_2:{b:'b'}}) @@ -666,11 +661,10 @@ function getCollectionDataAndSendAsObject(matchingKeys, mapping) { * @param {Boolean} [mapping.initWithStoredValues] If set to false, then no data will be prefilled into the * component * @param {Boolean} [mapping.waitForCollectionCallback] If set to true, it will return the entire collection to the callback as a single object - * @param {String|Function} [mapping.selector] THIS PARAM IS ONLY USED WITH withOnyx(). If included, this will be used to subscribe to a subset of an Onyx key's data. - * If the selector is a string, the selector is passed to lodashGet on the sourceData. If the selector is a function, the sourceData and withOnyx state are - * passed to the selector and should return the simplified data. Using this setting on `withOnyx` can have very positive performance benefits because the component - * will only re-render when the subset of data changes. Otherwise, any change of data on any property would normally cause the component to re-render (and that can - * be expensive from a performance standpoint). + * @param {Function} [mapping.selector] THIS PARAM IS ONLY USED WITH withOnyx(). If included, this will be used to subscribe to a subset of an Onyx key's data. + * The sourceData and withOnyx state are passed to the selector and should return the simplified data. Using this setting on `withOnyx` can have very positive + * performance benefits because the component will only re-render when the subset of data changes. Otherwise, any change of data on any property would normally + * cause the component to re-render (and that can be expensive from a performance standpoint). * @returns {Number} an ID to use when calling disconnect */ function connect(mapping) { diff --git a/package-lock.json b/package-lock.json index 0e99bd99f..97c88ad9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,6 @@ "dependencies": { "ascii-table": "0.0.9", "fast-equals": "^4.0.3", - "lodash": "^4.17.21", "underscore": "^1.13.1" }, "devDependencies": { @@ -11111,7 +11110,8 @@ "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true }, "node_modules/lodash.camelcase": { "version": "4.3.0", @@ -25617,7 +25617,8 @@ "lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true }, "lodash.camelcase": { "version": "4.3.0", diff --git a/package.json b/package.json index 453596ac6..ed3f4c774 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,6 @@ "dependencies": { "ascii-table": "0.0.9", "fast-equals": "^4.0.3", - "lodash": "^4.17.21", "underscore": "^1.13.1" }, "devDependencies": { diff --git a/tests/unit/subscribeToPropertiesTest.js b/tests/unit/subscribeToPropertiesTest.js index 557c28cfb..9eb93be99 100644 --- a/tests/unit/subscribeToPropertiesTest.js +++ b/tests/unit/subscribeToPropertiesTest.js @@ -90,16 +90,6 @@ describe('Only the specific property changes when using withOnyx() and ', () => }); }; - it('connecting to a single non-collection key with a selector string', () => { - const TestComponentWithOnyx = withOnyx({ - propertyA: { - key: ONYX_KEYS.TEST_KEY, - selector: 'a', - }, - })(ViewWithObject); - return runAssertionsWithComponent(TestComponentWithOnyx); - }); - it('connecting to a single non-collection key with a selector function', () => { const mockedSelector = jest.fn(obj => obj && obj.a); const TestComponentWithOnyx = withOnyx({ @@ -171,16 +161,6 @@ describe('Only the specific property changes when using withOnyx() and ', () => }); }; - it('connecting to a collection with a selector string', () => { - const TestComponentWithOnyx = withOnyx({ - collectionWithPropertyA: { - key: ONYX_KEYS.COLLECTION.TEST_KEY, - selector: 'a', - }, - })(ViewWithObject); - return runAllAssertionsForCollection(TestComponentWithOnyx); - }); - it('connecting to a collection with a selector function', () => { const mockedSelector = jest.fn(obj => obj && obj.a); const TestComponentWithOnyx = withOnyx({ @@ -259,16 +239,6 @@ describe('Only the specific property changes when using withOnyx() and ', () => }); }; - it('connecting to a collection member with a selector string', () => { - const TestComponentWithOnyx = withOnyx({ - itemWithPropertyA: { - key: `${ONYX_KEYS.COLLECTION.TEST_KEY}1`, - selector: 'a', - }, - })(ViewWithObject); - return runAllAssertionsForCollectionMemberKey(TestComponentWithOnyx); - }); - it('connecting to a collection member with a selector function', () => { const TestComponentWithOnyx = withOnyx({ itemWithPropertyA: {