Skip to content

Commit

Permalink
fix: instance option cache
Browse files Browse the repository at this point in the history
condition parsing in editor\n resolve #310
  • Loading branch information
kevinchappell committed Nov 19, 2024
1 parent 57a9028 commit b1d07e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
17 changes: 9 additions & 8 deletions src/lib/js/components/autocomplete.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import { toTitleCase } from '../common/utils/string.mjs'
const BASE_NAME = 'f-autocomplete'
const HIGHLIGHT_CLASS_NAME = 'highlight-component'

let lastCache = Date.now()
let optionsCache

/**
* Counts the number of occurences of a string in an array of strings
* @param {Array} arr labels
Expand Down Expand Up @@ -93,6 +90,8 @@ export const componentOptions = selectedId => {
* Output an autocomplete form element
*/
export default class Autocomplete {
lastCache = Date.now()
optionsCache = null
/**
* Create an Autocomplete instance
* @param {String} key - The key for the autocomplete instance
Expand Down Expand Up @@ -201,6 +200,8 @@ export default class Autocomplete {

this.hiddenField.value = value
this.value = value

this.setValue({ dataset: { label: value, value } })
},
}

Expand Down Expand Up @@ -244,13 +245,13 @@ export default class Autocomplete {
}

updateOptions() {
let options = optionsCache
let options = this.optionsCache
const now = Date.now()

if (!options || now - lastCache > ANIMATION_SPEED_SLOW * 10) {
if (!options || now - this.lastCache > ANIMATION_SPEED_SLOW * 10) {
dom.empty(this.list)
options = this.generateOptions()
lastCache = now
this.lastCache = now
}

if (!this.list.children.length) {
Expand All @@ -268,7 +269,7 @@ export default class Autocomplete {
return target
}

optionsCache = options.map(optionData => {
this.optionsCache = options.map(optionData => {
const { value, textLabel, htmlLabel } = optionData
const optionConfig = {
tag: 'li',
Expand All @@ -295,7 +296,7 @@ export default class Autocomplete {
return dom.create(optionConfig)
})

return optionsCache
return this.optionsCache
}

setListPosition() {
Expand Down
7 changes: 3 additions & 4 deletions src/lib/js/components/fields/edit-panel-item.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,10 @@ export default class EditPanelItem {
}

const conditionChangeAction = ({ target }) => {
const row = target.closest('.f-condition-row')
const conditionRow = target.closest('.f-condition-row')
const regex = new RegExp(`${target.className}(?:\\S?)+`, 'gm')
row.className = row.className.replace(regex, '')
row.classList.add([target.className, target.value].filter(Boolean).join('-'))
conditionRow.className = conditionRow.className.replace(regex, '')

const evtData = {
dataPath,
value: target.value,
Expand All @@ -341,7 +341,6 @@ export default class EditPanelItem {
events.formeoUpdated(evtData)
Components.setAddress(dataPath, target.value)

const conditionRow = target.closest('.f-condition-row')
const rowIndex = indexOfNode(conditionRow)
this.processConditionUIState(this.itemFieldGroups[rowIndex])
}
Expand Down

0 comments on commit b1d07e1

Please sign in to comment.