From afe95b269bfb49a6b26f9afcd06d1bbd37fa8024 Mon Sep 17 00:00:00 2001 From: sacr3dc0w Date: Mon, 5 Sep 2022 19:23:10 -0700 Subject: [PATCH] Reduce lodash usage --- CHANGELOG.md | 1 + assets/js/theme/common/faceted-search.js | 6 +++--- assets/js/theme/common/nod-functions/min-max-validate.js | 4 +--- assets/js/theme/common/product-details-base.js | 7 +++---- assets/js/theme/common/state-country.js | 2 +- assets/js/theme/common/utils/form-utils.js | 2 +- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 042144df6f..b1f1109ec4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add global region below the navigation in the header [#2231](https://github.com/bigcommerce/cornerstone/pull/2231) - Fixed escaping on created store account confirm message. [#2248]https://github.com/bigcommerce/cornerstone/pull/2248 - Pass theme settings from blog page to blog post template. [#2253]https://github.com/bigcommerce/cornerstone/pull/2253 +- Reduce lodash usage [#2256]https://github.com/bigcommerce/cornerstone/pull/2256 ## 6.5.0 (06-24-2022) - Category icons do not appear in Search Form [#2221]https://github.com/bigcommerce/cornerstone/pull/2221 diff --git a/assets/js/theme/common/faceted-search.js b/assets/js/theme/common/faceted-search.js index f2f70dbcda..48b51505db 100644 --- a/assets/js/theme/common/faceted-search.js +++ b/assets/js/theme/common/faceted-search.js @@ -156,7 +156,7 @@ class FacetedSearch { const id = $navList.attr('id'); // Toggle depending on `collapsed` flag - if (_.includes(this.collapsedFacetItems, id)) { + if (this.collapsedFacetItems.includes(id)) { this.getMoreFacetResults($navList); return true; @@ -266,7 +266,7 @@ class FacetedSearch { $navLists.each((index, navList) => { const $navList = $(navList); const id = $navList.attr('id'); - const shouldCollapse = _.includes(this.collapsedFacetItems, id); + const shouldCollapse = this.collapsedFacetItems.includes(id); if (shouldCollapse) { this.collapseFacetItems($navList); @@ -283,7 +283,7 @@ class FacetedSearch { const $accordionToggle = $(accordionToggle); const collapsible = $accordionToggle.data('collapsibleInstance'); const id = collapsible.targetId; - const shouldCollapse = _.includes(this.collapsedFacets, id); + const shouldCollapse = this.collapsedFacets.includes(id); if (shouldCollapse) { this.collapseFacet($accordionToggle); diff --git a/assets/js/theme/common/nod-functions/min-max-validate.js b/assets/js/theme/common/nod-functions/min-max-validate.js index a72488cfe7..1d3e34aeec 100644 --- a/assets/js/theme/common/nod-functions/min-max-validate.js +++ b/assets/js/theme/common/nod-functions/min-max-validate.js @@ -1,11 +1,9 @@ -import _ from 'lodash'; - function minMaxValidate(minInputSelector, maxInputSelector) { function validate(cb) { const minValue = parseFloat($(minInputSelector).val()); const maxValue = parseFloat($(maxInputSelector).val()); - if (maxValue > minValue || _.isNaN(maxValue) || _.isNaN(minValue)) { + if (maxValue > minValue || Number.isNaN(maxValue) || Number.isNaN(minValue)) { return cb(true); } diff --git a/assets/js/theme/common/product-details-base.js b/assets/js/theme/common/product-details-base.js index 71982946e7..98cac84b0d 100644 --- a/assets/js/theme/common/product-details-base.js +++ b/assets/js/theme/common/product-details-base.js @@ -1,6 +1,5 @@ import Wishlist from '../wishlist'; import { initRadioOptions } from './aria'; -import { isObject, isNumber } from 'lodash'; const optionsTypesMap = { INPUT_FILE: 'input-file', @@ -214,11 +213,11 @@ export default class ProductDetailsBase { this.showMessageBox(data.stock_message || data.purchasing_message); - if (isObject(data.price)) { + if (data.price instanceof Object) { this.updatePriceView(viewModel, data.price); } - if (isObject(data.weight)) { + if (data.weight instanceof Object) { viewModel.$weight.html(data.weight.formatted); } @@ -246,7 +245,7 @@ export default class ProductDetailsBase { } // if stock view is on (CP settings) - if (viewModel.stock.$container.length && isNumber(data.stock)) { + if (viewModel.stock.$container.length && typeof data.stock === 'number') { // if the stock container is hidden, show viewModel.stock.$container.removeClass('u-hiddenVisually'); diff --git a/assets/js/theme/common/state-country.js b/assets/js/theme/common/state-country.js index da9bc65080..caea782285 100644 --- a/assets/js/theme/common/state-country.js +++ b/assets/js/theme/common/state-country.js @@ -86,7 +86,7 @@ function addOptions(statesArray, $selectElement, options) { container.push(``); if (!_.isEmpty($selectElement)) { - _.each(statesArray.states, (stateObj) => { + statesArray.states.forEach((stateObj) => { if (options.useIdForStates) { container.push(``); } else { diff --git a/assets/js/theme/common/utils/form-utils.js b/assets/js/theme/common/utils/form-utils.js index bebb29a536..5686dfff77 100644 --- a/assets/js/theme/common/utils/form-utils.js +++ b/assets/js/theme/common/utils/form-utils.js @@ -41,7 +41,7 @@ function classifyInput(input, formFieldClass) { if (tagName === 'input') { const inputType = $input.prop('type'); - if (_.includes(['radio', 'checkbox', 'submit'], inputType)) { + if (['radio', 'checkbox', 'submit'].includes(inputType)) { // ie: .form-field--checkbox, .form-field--radio className = `${formFieldClass}--${_.camelCase(inputType)}`; } else {