@maskito/vue
Version:
The Vue-specific Maskito's library
34 lines (31 loc) • 1.18 kB
JavaScript
import { MASKITO_DEFAULT_ELEMENT_PREDICATE, Maskito } from '@maskito/core';
const teardown = new Map();
const predicates = new Map();
async function update(element, options) {
var _a, _b;
const predicate = (_a = options === null || options === void 0 ? void 0 : options.elementPredicate) !== null && _a !== void 0 ? _a : MASKITO_DEFAULT_ELEMENT_PREDICATE;
predicates.set(element, predicate);
const predicateResult = await predicate(element);
if (predicates.get(element) !== predicate) {
return;
}
(_b = teardown.get(element)) === null || _b === void 0 ? void 0 : _b.destroy();
if (options) {
teardown.set(element, new Maskito(predicateResult, options));
}
}
const maskito = {
unmounted: (element) => {
var _a;
(_a = teardown.get(element)) === null || _a === void 0 ? void 0 : _a.destroy();
teardown.delete(element);
predicates.delete(element);
},
mounted: async (element, { value }) => update(element, value),
updated: async (element, { value, oldValue }) => {
if (value !== oldValue) {
await update(element, value);
}
},
};
export { maskito };