Refactor emitters

This commit is contained in:
Montana 2019-04-19 11:33:51 -04:00
parent 39975a0a31
commit 629dd674b9
6 changed files with 22 additions and 20 deletions

View File

@ -1,4 +1,4 @@
import { emitFieldChange } from '../lib/emitters' import { emitEvent } from '../lib/emitters'
export default { export default {
name: 'checkboxinput', name: 'checkboxinput',
@ -9,7 +9,10 @@ export default {
methods: { methods: {
onInput: function(e) { onInput: function(e) {
emitFieldChange(this, { value: e.target.checked, name: this.name }) emitEvent('field-change', this, {
value: e.target.checked,
name: this.name,
})
}, },
}, },
} }

View File

@ -1,6 +1,6 @@
import Vue from 'vue' import Vue from 'vue'
import { getDaysInMonth } from 'date-fns' import { getDaysInMonth } from 'date-fns'
import { emitFieldChange } from '../lib/emitters' import { emitEvent } from '../lib/emitters'
var paddedNumber = function(number) { var paddedNumber = function(number) {
if ((number + '').length === 1) { if ((number + '').length === 1) {
@ -136,7 +136,7 @@ export default {
methods: { methods: {
_emitChange: function(name, value, valid) { _emitChange: function(name, value, valid) {
emitFieldChange(this, { value, name }) emitEvent('field-change', this, { value, name })
}, },
}, },

View File

@ -1,6 +1,6 @@
import optionsinput from '../components/options_input' import optionsinput from '../components/options_input'
import textinput from '../components/text_input' import textinput from '../components/text_input'
import { emitFieldChange } from '../lib/emitters' import { emitEvent } from '../lib/emitters'
export default { export default {
name: 'multicheckboxinput', name: 'multicheckboxinput',
@ -41,7 +41,10 @@ export default {
methods: { methods: {
onInput: function(e) { onInput: function(e) {
emitFieldChange(this, { value: e.target.value, name: this.name }) emitEvent('field-change', this, {
value: e.target.value,
name: this.name,
})
this.showError = false this.showError = false
this.showValid = true this.showValid = true
}, },

View File

@ -1,4 +1,4 @@
import { emitFieldChange } from '../lib/emitters' import { emitEvent } from '../lib/emitters'
export default { export default {
name: 'optionsinput', name: 'optionsinput',
@ -23,7 +23,10 @@ export default {
methods: { methods: {
onInput: function(e) { onInput: function(e) {
emitFieldChange(this, { value: e.target.value, name: this.name }) emitEvent('field-change', this, {
value: e.target.value,
name: this.name,
})
this.showError = false this.showError = false
this.showValid = true this.showValid = true
}, },

View File

@ -1,7 +1,7 @@
import MaskedInput, { conformToMask } from 'vue-text-mask' import MaskedInput, { conformToMask } from 'vue-text-mask'
import inputValidations from '../lib/input_validations' import inputValidations from '../lib/input_validations'
import { formatDollars } from '../lib/dollars' import { formatDollars } from '../lib/dollars'
import { emitFieldChange, emitFieldMount } from '../lib/emitters' import { emitEvent } from '../lib/emitters'
export default { export default {
name: 'textinput', name: 'textinput',
@ -68,7 +68,7 @@ export default {
}, },
created: function() { created: function() {
emitFieldMount(this, { emitEvent('field-mount', this, {
optional: this.optional, optional: this.optional,
name: this.name, name: this.name,
}) })
@ -126,7 +126,7 @@ export default {
this.showValid = this.value != '' && valid this.showValid = this.value != '' && valid
// Emit a change event // Emit a change event
emitFieldChange(this, { emitEvent('field-change', this, {
value: this._rawValue(value), value: this._rawValue(value),
valid, valid,
name: this.name, name: this.name,

View File

@ -1,12 +1,5 @@
export const emitFieldChange = (el, data) => { export const emitEvent = (event_type, el, data) => {
el.$root.$emit('field-change', { el.$root.$emit(event_type, {
...data,
parent_uid: el.$parent && el.$parent._uid,
})
}
export const emitFieldMount = (el, data) => {
el.$root.$emit('field-mount', {
...data, ...data,
parent_uid: el.$parent && el.$parent._uid, parent_uid: el.$parent && el.$parent._uid,
}) })