Skip to content

Commit

Permalink
Minor code improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Hotze <[email protected]>
  • Loading branch information
florian-h05 committed Oct 15, 2023
1 parent e8b5d5f commit cff8b33
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default {
},
computed: {
value () {
const applyOffset = (value) => (typeof this.config.offset === 'number') ? Number(this.toStepFixed(value + this.config.offset)) : value
const applyOffset = (num) => (!isNaN(this.config.offset)) ? Number(this.toStepFixed(num + Number(this.config.offset))) : num
if (this.config.variable) {
if (this.config.variableKey) {
return applyOffset(this.getLastVariableKeyValue(this.context.vars[this.config.variable], this.config.variableKey))
Expand All @@ -48,10 +48,11 @@ export default {
// uses the number of decimals in the step config to round the provided number
if (!this.config.step) return value
const nbDecimals = Number(this.config.step).toString().replace(',', '.').split('.')[1]
return parseFloat(Number(value)).toFixed(nbDecimals ? nbDecimals.length : 0)
// do NOT convert to number, instead return string, otherwise formatting wouldn't work
return parseFloat(value).toFixed(nbDecimals ? nbDecimals.length : 0)
},
onChange (value) {
const applyOffset = (value) => (typeof this.config.offset === 'number') ? Number(this.toStepFixed(value - this.config.offset)) : value
const applyOffset = (num) => (!isNaN(this.config.offset)) ? Number(this.toStepFixed(num - Number(this.config.offset))) : num
let newValue = applyOffset(Number(this.toStepFixed(value)))
if (isNaN(newValue)) newValue = this.config.min || this.config.max || 0
if (newValue === this.value) return
Expand Down

0 comments on commit cff8b33

Please sign in to comment.