2
0
mirror of https://github.com/tenrok/maska.git synced 2026-06-11 18:02:27 +03:00

Fix #31: mask value on v-model change

This commit is contained in:
Alexander Shabunevich
2021-07-09 12:13:02 +03:00
parent e3c87c4026
commit 0355016b35
9 changed files with 26 additions and 18 deletions
+12 -4
View File
@@ -22,10 +22,18 @@ function needUpdate (mask) {
)
}
export default function directive (el, mask) {
if (!mask.value) return
const directive = () => {
const state = new WeakMap()
if (mask.value && needUpdate(mask)) {
return new Maska(el, getOpts(mask.value))
return (el, mask) => {
if (!mask.value) return
if (state.has(el) && !needUpdate(mask)) {
return state.get(el).updateValue(el)
}
state.set(el, new Maska(el, getOpts(mask.value)))
}
}
export default directive()