-
Notifications
You must be signed in to change notification settings - Fork 19
Remove lodash #800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Remove lodash #800
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,18 +50,18 @@ Fliplet.FormBuilder.field('checkbox', { | |
var $vm = this; | ||
|
||
// Sort selected options by their index as a checkbox input option | ||
var ordered = _.sortBy(this.value, function(val) { | ||
return _.findIndex($vm.options, function(option) { | ||
var ordered = this.sortBy(this.value, function(val) { | ||
return $vm.options.findIndex(function(option) { | ||
return (option.id || option.label) === val; | ||
}); | ||
}); | ||
|
||
// Get all options label in array format | ||
var allOptions = _.map(this.options, function(option) { | ||
var allOptions = this.options.map(function(option) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @armine-fliplet Same with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Arpanexe type of |
||
return option.id || option.label; | ||
}); | ||
|
||
this.selectedAll = _.isEqual(ordered, allOptions); | ||
this.selectedAll = this.isEqual(ordered, allOptions); | ||
} | ||
}, | ||
selectedAll: { | ||
|
@@ -83,7 +83,7 @@ Fliplet.FormBuilder.field('checkbox', { | |
this.value = []; | ||
} | ||
|
||
if (!_.isEqual(oldValue, this.value)) { | ||
if (!this.isEqual(oldValue, this.value)) { | ||
this.updateValue(); | ||
} | ||
} | ||
|
@@ -101,12 +101,89 @@ Fliplet.FormBuilder.field('checkbox', { | |
return rules; | ||
}, | ||
methods: { | ||
/** | ||
* Sorts an array based on iteratee function results | ||
* @param {Array} array - array to sort | ||
* @param {Function} iteratee - function to determine sort value | ||
* @returns {Array} sorted array | ||
*/ | ||
sortBy: function(array, iteratee) { | ||
return array.slice().sort(function(a, b) { | ||
var valueA = iteratee(a); | ||
var valueB = iteratee(b); | ||
|
||
if (valueA < valueB) return -1; | ||
if (valueA > valueB) return 1; | ||
|
||
return 0; | ||
}); | ||
}, | ||
|
||
/** | ||
* Performs deep equality comparison | ||
* @param {*} a - first value | ||
* @param {*} b - second value | ||
* @returns {Boolean} true if equal | ||
*/ | ||
isEqual: function(a, b) { | ||
if (a === b) return true; | ||
if (a === null || b === null) return false; | ||
|
||
if (Array.isArray(a) && Array.isArray(b)) { | ||
if (a.length !== b.length) return false; | ||
|
||
for (var i = 0; i < a.length; i++) { | ||
if (!this.isEqual(a[i], b[i])) return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
if (typeof a === 'object' && typeof b === 'object') { | ||
var keysA = Object.keys(a); | ||
var keysB = Object.keys(b); | ||
|
||
if (keysA.length !== keysB.length) return false; | ||
|
||
for (var key of keysA) { | ||
if (!Object.prototype.hasOwnProperty.call(b, key) || !this.isEqual(a[key], b[key])) return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
}, | ||
|
||
/** | ||
* Creates unique array using comparator function | ||
* @param {Array} array - array to make unique | ||
* @param {Function} comparator - function to compare elements | ||
* @returns {Array} unique array | ||
*/ | ||
uniqueWith: function(array, comparator) { | ||
var result = []; | ||
var $vm = this; | ||
|
||
array.forEach(function(item) { | ||
var isDuplicate = result.some(function(existing) { | ||
return comparator.call($vm, item, existing); | ||
}); | ||
|
||
if (!isDuplicate) { | ||
result.push(item); | ||
} | ||
}); | ||
|
||
return result; | ||
}, | ||
Comment on lines
+104
to
+179
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) 🛠️ Refactor suggestion Add comprehensive unit tests for new utility methods. The three new utility methods ( Test scenarios needed:
Consider extracting these utilities to a shared module to avoid duplication across components. 🧰 Tools🪛 Biome (1.9.4)[error] 112-112: Use let or const instead of var. A variable declared with var is accessible in the whole body of the function. Thus, the variable can be accessed before its initialization and outside the block where it is declared. (lint/style/noVar) [error] 113-113: Use let or const instead of var. A variable declared with var is accessible in the whole body of the function. Thus, the variable can be accessed before its initialization and outside the block where it is declared. (lint/style/noVar) [error] 135-135: Use let or const instead of var. A variable declared with var is accessible in the whole body of the function. Thus, the variable can be accessed before its initialization and outside the block where it is declared. (lint/style/noVar) [error] 143-143: Use let or const instead of var. A variable declared with var is accessible in the whole body of the function. Thus, the variable can be accessed before its initialization and outside the block where it is declared. (lint/style/noVar) [error] 144-144: Use let or const instead of var. A variable declared with var is accessible in the whole body of the function. Thus, the variable can be accessed before its initialization and outside the block where it is declared. (lint/style/noVar) [error] 148-148: Use let or const instead of var. A variable declared with var is accessible in the whole body of the function. Thus, the variable can be accessed before its initialization and outside the block where it is declared. (lint/style/noVar) [error] 165-165: Use let or const instead of var. A variable declared with var is accessible in the whole body of the function. Thus, the variable can be accessed before its initialization and outside the block where it is declared. (lint/style/noVar) [error] 166-166: Use let or const instead of var. A variable declared with var is accessible in the whole body of the function. Thus, the variable can be accessed before its initialization and outside the block where it is declared. (lint/style/noVar) [error] 169-171: Use let or const instead of var. A variable declared with var is accessible in the whole body of the function. Thus, the variable can be accessed before its initialization and outside the block where it is declared. (lint/style/noVar) 🤖 Prompt for AI Agents
|
||
|
||
updateValue: function() { | ||
var $vm = this; | ||
|
||
// Sort selected options by their index as a checkbox input option | ||
var ordered = _.sortBy(this.value, function(val) { | ||
return _.findIndex($vm.options, function(option) { | ||
var ordered = this.sortBy(this.value, function(val) { | ||
return $vm.options.findIndex(function(option) { | ||
return (option.label || option.id) === val; | ||
}); | ||
}); | ||
|
@@ -148,16 +225,16 @@ Fliplet.FormBuilder.field('checkbox', { | |
var selectedOptions = []; | ||
|
||
this.value.forEach(function(value) { | ||
var selectedOption = _.find($vm.options, function(option) { | ||
return (_.has(option, 'label') && _.has(option, 'id')) ? option.id === value : option.label === value; | ||
var selectedOption = $vm.options.find(function(option) { | ||
return (Object.prototype.hasOwnProperty.call(option, 'label') && Object.prototype.hasOwnProperty.call(option, 'id')) ? option.id === value : option.label === value; | ||
}); | ||
|
||
if (selectedOption) { | ||
selectedOptions.push(selectedOption); | ||
} | ||
}); | ||
|
||
this.value = selectedOptions.length ? _.uniqWith(this.value, _.isEqual) : []; | ||
this.value = selectedOptions.length ? this.uniqueWith(this.value, this.isEqual) : []; | ||
} | ||
|
||
if (!!this.defaultValue) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@armine-fliplet Could you please confirm if this change will work? I assume
$vm.options
doesn’t have afindIndex
function unless it is string or Array.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Arpanexe type of
$vm.options
is Array