import isEqual from 'lodash.isequal'; import isUndefined from 'lodash.isundefined'; import isArray from 'lodash.isarray'; import isObject from 'lodash.isobject'; import cloneDeep from 'lodash.clonedeep'; export const setBindingValue = (binding, options, initialOptions, firstProperty, secondProperty) => { if (!isUndefined(binding.oldValue) && !isUndefined(binding.oldValue[firstProperty]) && binding.oldValue[firstProperty] === binding.value[firstProperty] ) { return; } if (binding.value) { options[firstProperty] = !isUndefined(binding.value[firstProperty]) ? binding.value[firstProperty] : initialOptions[secondProperty]; } }; export const setBindingObjectValue = (binding, options, initialOptions, firstProperty, secondProperty) => { if (!isUndefined(binding.oldValue) && !isUndefined(binding.oldValue[firstProperty]) && isEqual(binding.oldValue[firstProperty], binding.value[firstProperty]) ) { return; } if (binding.value) { options[firstProperty] = !isUndefined(binding.value[firstProperty]) && (isObject(binding.value[firstProperty]) && !isArray(binding.value[firstProperty])) ? cloneDeep(binding.value[firstProperty]) : cloneDeep(initialOptions[secondProperty]); } }; export const setBindingArrayValue = (binding, options, initialOptions, firstProperty, secondProperty) => { if (!isUndefined(binding.oldValue) && !isUndefined(binding.oldValue[firstProperty]) && isEqual(binding.oldValue[firstProperty], binding.value[firstProperty]) ) { return; } if (binding.value) { options[firstProperty] = (!isUndefined(binding.value[firstProperty]) && isArray(binding.value[firstProperty])) ? cloneDeep(binding.value[firstProperty]) : cloneDeep(initialOptions[secondProperty]); } }; export const setClassValue = (element, binding, options, initialOptions, firstProperty, secondProperty) => { if (!isUndefined(binding.oldValue) && !isUndefined(binding.oldValue[firstProperty]) && binding.oldValue[firstProperty] === binding.value[firstProperty] ) { return; } if (!isUndefined(binding.value)) { const oldClass = options[firstProperty]; if (element.classList.contains(oldClass)) { element.classList.remove(oldClass); } options[firstProperty] = !isUndefined(binding.value[firstProperty]) ? binding.value[firstProperty] : initialOptions[secondProperty]; if (options[firstProperty] !== '') { element.classList.add(options[firstProperty]); } } else { if (options[firstProperty] !== '') { element.classList.add(options[firstProperty]); } } }; export const setBindingModifier = (binding, modifiers, initialModifiers, firstProperty, secondProperty) => { if (binding.modifiers) { modifiers[firstProperty] = !isUndefined(binding.modifiers[secondProperty]) ? binding.modifiers[secondProperty] : initialModifiers[firstProperty]; } };