Skip to content

Commit b1d07e1

Browse files
committed
fix: instance option cache
condition parsing in editor\n resolve #310
1 parent 57a9028 commit b1d07e1

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/lib/js/components/autocomplete.mjs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import { toTitleCase } from '../common/utils/string.mjs'
88
const BASE_NAME = 'f-autocomplete'
99
const HIGHLIGHT_CLASS_NAME = 'highlight-component'
1010

11-
let lastCache = Date.now()
12-
let optionsCache
13-
1411
/**
1512
* Counts the number of occurences of a string in an array of strings
1613
* @param {Array} arr labels
@@ -93,6 +90,8 @@ export const componentOptions = selectedId => {
9390
* Output an autocomplete form element
9491
*/
9592
export default class Autocomplete {
93+
lastCache = Date.now()
94+
optionsCache = null
9695
/**
9796
* Create an Autocomplete instance
9897
* @param {String} key - The key for the autocomplete instance
@@ -201,6 +200,8 @@ export default class Autocomplete {
201200

202201
this.hiddenField.value = value
203202
this.value = value
203+
204+
this.setValue({ dataset: { label: value, value } })
204205
},
205206
}
206207

@@ -244,13 +245,13 @@ export default class Autocomplete {
244245
}
245246

246247
updateOptions() {
247-
let options = optionsCache
248+
let options = this.optionsCache
248249
const now = Date.now()
249250

250-
if (!options || now - lastCache > ANIMATION_SPEED_SLOW * 10) {
251+
if (!options || now - this.lastCache > ANIMATION_SPEED_SLOW * 10) {
251252
dom.empty(this.list)
252253
options = this.generateOptions()
253-
lastCache = now
254+
this.lastCache = now
254255
}
255256

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

271-
optionsCache = options.map(optionData => {
272+
this.optionsCache = options.map(optionData => {
272273
const { value, textLabel, htmlLabel } = optionData
273274
const optionConfig = {
274275
tag: 'li',
@@ -295,7 +296,7 @@ export default class Autocomplete {
295296
return dom.create(optionConfig)
296297
})
297298

298-
return optionsCache
299+
return this.optionsCache
299300
}
300301

301302
setListPosition() {

src/lib/js/components/fields/edit-panel-item.mjs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,10 @@ export default class EditPanelItem {
328328
}
329329

330330
const conditionChangeAction = ({ target }) => {
331-
const row = target.closest('.f-condition-row')
331+
const conditionRow = target.closest('.f-condition-row')
332332
const regex = new RegExp(`${target.className}(?:\\S?)+`, 'gm')
333-
row.className = row.className.replace(regex, '')
334-
row.classList.add([target.className, target.value].filter(Boolean).join('-'))
333+
conditionRow.className = conditionRow.className.replace(regex, '')
334+
335335
const evtData = {
336336
dataPath,
337337
value: target.value,
@@ -341,7 +341,6 @@ export default class EditPanelItem {
341341
events.formeoUpdated(evtData)
342342
Components.setAddress(dataPath, target.value)
343343

344-
const conditionRow = target.closest('.f-condition-row')
345344
const rowIndex = indexOfNode(conditionRow)
346345
this.processConditionUIState(this.itemFieldGroups[rowIndex])
347346
}

0 commit comments

Comments
 (0)