fix: Got rid of redundant input events
This commit is contained in:
parent
b1c2ee9056
commit
b4ab3404a4
@ -39,6 +39,7 @@ const VALIDATION_BEHAVIOR = {
|
|||||||
export default class FormularioField extends Vue {
|
export default class FormularioField extends Vue {
|
||||||
@Inject({ default: '' }) __Formulario_path!: string
|
@Inject({ default: '' }) __Formulario_path!: string
|
||||||
@Inject({ default: undefined }) __FormularioForm_set!: Function|undefined
|
@Inject({ default: undefined }) __FormularioForm_set!: Function|undefined
|
||||||
|
@Inject({ default: () => (): void => {} }) __FormularioForm_emitInput!: Function
|
||||||
@Inject({ default: () => (): void => {} }) __FormularioForm_emitValidation!: Function
|
@Inject({ default: () => (): void => {} }) __FormularioForm_emitValidation!: Function
|
||||||
@Inject({ default: undefined }) __FormularioForm_register!: Function|undefined
|
@Inject({ default: undefined }) __FormularioForm_register!: Function|undefined
|
||||||
@Inject({ default: undefined }) __FormularioForm_unregister!: Function|undefined
|
@Inject({ default: undefined }) __FormularioForm_unregister!: Function|undefined
|
||||||
@ -96,12 +97,12 @@ export default class FormularioField extends Vue {
|
|||||||
|
|
||||||
if (!shallowEquals(value, this.proxy)) {
|
if (!shallowEquals(value, this.proxy)) {
|
||||||
this.proxy = value
|
this.proxy = value
|
||||||
}
|
|
||||||
|
|
||||||
this.$emit('input', value)
|
this.$emit('input', value)
|
||||||
|
|
||||||
if (typeof this.__FormularioForm_set === 'function') {
|
if (typeof this.__FormularioForm_set === 'function') {
|
||||||
this.__FormularioForm_set(this.fullPath, value)
|
this.__FormularioForm_set(this.fullPath, value)
|
||||||
|
this.__FormularioForm_emitInput()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,8 @@ export default class FormularioForm extends Vue {
|
|||||||
if (!field.hasModel && this.modelIsDefined && value !== undefined) {
|
if (!field.hasModel && this.modelIsDefined && value !== undefined) {
|
||||||
field.model = value
|
field.model = value
|
||||||
} else if (field.hasModel && !shallowEquals(field.proxy, value)) {
|
} else if (field.hasModel && !shallowEquals(field.proxy, value)) {
|
||||||
this.setFieldValueAndEmit(path, field.proxy)
|
this.setFieldValue(path, field.proxy)
|
||||||
|
this.emitInput()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has(this.fieldsErrorsComputed, path)) {
|
if (has(this.fieldsErrorsComputed, path)) {
|
||||||
@ -111,8 +112,18 @@ export default class FormularioForm extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Provide('__FormularioForm_set')
|
@Provide('__FormularioForm_set')
|
||||||
private setFieldValueAndEmit (field: string, value: unknown): void {
|
private setFieldValue (field: string, value: unknown): void {
|
||||||
this.setFieldValue(field, value)
|
if (value === undefined) {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
const { [field]: value, ...proxy } = this.proxy
|
||||||
|
this.proxy = proxy
|
||||||
|
} else {
|
||||||
|
setNested(this.proxy, field, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provide('__FormularioForm_emitInput')
|
||||||
|
private emitInput (): void {
|
||||||
this.$emit('input', { ...this.proxy })
|
this.$emit('input', { ...this.proxy })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,15 +231,5 @@ export default class FormularioForm extends Vue {
|
|||||||
this.proxy = this.modelCopy
|
this.proxy = this.modelCopy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private setFieldValue (field: string, value: unknown): void {
|
|
||||||
if (value === undefined) {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
const { [field]: value, ...proxy } = this.proxy
|
|
||||||
this.proxy = proxy
|
|
||||||
} else {
|
|
||||||
setNested(this.proxy, field, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -282,12 +282,8 @@ describe('FormularioField', () => {
|
|||||||
|
|
||||||
const form = wrapper.findComponent(FormularioForm)
|
const form = wrapper.findComponent(FormularioForm)
|
||||||
|
|
||||||
// @TODO: investigate where redundant events come from
|
|
||||||
expect(form.emitted('input')).toEqual([
|
expect(form.emitted('input')).toEqual([
|
||||||
[{}],
|
[{}],
|
||||||
[{}],
|
|
||||||
[{ date: new Date('2001-05-12') }],
|
|
||||||
[{ date: new Date('2001-05-12') }],
|
|
||||||
[{ date: new Date('2001-05-12') }],
|
[{ date: new Date('2001-05-12') }],
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user