Skip to content

Commit

Permalink
fix: timeout memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinchappell committed Aug 22, 2020
1 parent 7e7569e commit 34fa376
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/js/control/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ export default class controlAutocomplete extends control {
},
blur: evt => {
evt.target.removeEventListener('keydown', keyboardNav)
setTimeout(() => {
const blurTimeout = setTimeout(() => {
evt.target.nextSibling.nextSibling.style.display = 'none'
clearTimeout(blurTimeout)
}, 200)
// Validate the option entered exists
if (this.config.requireValidOption) {
Expand Down
14 changes: 9 additions & 5 deletions src/js/form-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ const FormBuilder = function(opts, element, $) {
}

if (isNew) {
setTimeout(() => document.dispatchEvent(events.fieldAdded), 10)
const eventTimeout = setTimeout(() => {
document.dispatchEvent(events.fieldAdded)
clearTimeout(eventTimeout)
}, 10)
}

appendNewField(field, isNew)
Expand Down Expand Up @@ -347,8 +350,8 @@ const FormBuilder = function(opts, element, $) {
select: defaultAttrs.concat(['multiple', 'options']),
textarea: defaultAttrs.concat(['subtype', 'maxlength', 'rows']),
}
if((type in controls.registeredSubtypes) && !(type in typeAttrsMap)){

if (type in controls.registeredSubtypes && !(type in typeAttrsMap)) {
typeAttrsMap[type] = defaultAttrs.concat(['subtype'])
}

Expand Down Expand Up @@ -536,7 +539,7 @@ const FormBuilder = function(opts, element, $) {
number: numberAttribute,
boolean: (attr, attrData) => {
let isChecked = false
if(attr.type === 'checkbox'){
if (attr.type === 'checkbox') {
isChecked = Boolean(attrData.hasOwnProperty('value') ? attrData.value : false)
} else if (values.hasOwnProperty(attr)) {
isChecked = values[attr]
Expand Down Expand Up @@ -1396,12 +1399,13 @@ const FormBuilder = function(opts, element, $) {
// set min-height on stage onRender
d.onRender(d.controls, () => {
// Ensure style has loaded
setTimeout(() => {
const onRenderTimeout = setTimeout(() => {
d.stage.style.minHeight = `${d.controls.clientHeight}px`
// If option set, controls will remain in view in editor
if (opts.stickyControls.enable) {
h.stickyControls($stage)
}
clearTimeout(onRenderTimeout)
}, 0)
})

Expand Down
3 changes: 2 additions & 1 deletion src/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,10 @@ export default class Helpers {
let outerHeight = 0
forEach(fields, index => (outerHeight += fields[index].offsetHeight + 3))
fields[0].style.marginTop = `${-outerHeight}px`
setTimeout(() => {
const animateTimeout = setTimeout(() => {
empty(stage).classList.remove('removing')
this.save()
clearTimeout(animateTimeout)
}, 400)
} else {
empty(stage)
Expand Down

0 comments on commit 34fa376

Please sign in to comment.