@stackoverfloweth/vue-compositions
Version:
A collection of reusable vue compositions.
36 lines • 1.1 kB
JavaScript
import isEqual from 'lodash.isequal';
import { isRef, unref, watch } from 'vue';
import { isArray } from '../utilities/arrays';
import { isRecord, mapValues } from '../utilities/objects';
function getRawValue(value) {
if (typeof value === 'object') {
if (isRef(value)) {
return unref(value);
}
if (isArray(value)) {
return getRawArrayValue(value);
}
if (isRecord(value)) {
return getRawRecordValue(value);
}
}
return value;
}
function getRawArrayValue(values) {
return values.map(value => getRawValue(value));
}
function getRawRecordValue(value) {
return mapValues(value, (key, value) => getRawValue(value));
}
export function uniqueValueWatcher(...[source, callback, options]) {
let previous = getRawValue(source);
return watch(source, (...args) => {
const current = getRawValue(source);
if (isEqual(previous, current)) {
return;
}
previous = current;
callback(...args);
}, options);
}
//# sourceMappingURL=uniqueValueWatcher.js.map