Skip to content

Commit

Permalink
Reduce lodash usage (#2256)
Browse files Browse the repository at this point in the history
Co-authored-by: Volodymyr Krasnoshapka <88093058+BC-krasnoshapka@users.noreply.github.com>
  • Loading branch information
sacr3dc0w and BC-krasnoshapka authored Sep 7, 2022
1 parent 0d3c914 commit f31bec9
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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
- Bump jQuery to 3.6.1. [#2250](https://github.com/bigcommerce/cornerstone/issues/2250)
- 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
Expand Down
6 changes: 3 additions & 3 deletions assets/js/theme/common/faceted-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions assets/js/theme/common/nod-functions/min-max-validate.js
Original file line number Diff line number Diff line change
@@ -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);
}

Expand Down
7 changes: 3 additions & 4 deletions assets/js/theme/common/product-details-base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Wishlist from '../wishlist';
import { initRadioOptions } from './aria';
import { isObject, isNumber } from 'lodash';

const optionsTypesMap = {
INPUT_FILE: 'input-file',
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion assets/js/theme/common/state-country.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function addOptions(statesArray, $selectElement, options) {
container.push(`<option value="">${statesArray.prefix}</option>`);

if (!_.isEmpty($selectElement)) {
_.each(statesArray.states, (stateObj) => {
statesArray.states.forEach((stateObj) => {
if (options.useIdForStates) {
container.push(`<option value="${stateObj.id}">${stateObj.name}</option>`);
} else {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/theme/common/utils/form-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f31bec9

Please sign in to comment.