Skip to content

Commit

Permalink
clean parent watcher to mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre BERTRAND committed Aug 16, 2024
1 parent 3c0f04f commit 7d65892
Show file tree
Hide file tree
Showing 3 changed files with 1,483 additions and 76 deletions.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
"repository": "git@github.com:hublot-io/defineModel.git",
"author": "Alexandre BERTRAND <alexandre@hublot.io>",
"license": "MIT",
"private": false,
"scripts": {
"dev": "vite serve example"
},
"peerDependencies": {
"vue": "^2.7.0"
},
"vue": "^2.7.0"
},
"devDependencies": {
"vite": "^5.4.1",
"vue": "^2.7.0"
}
}
13 changes: 6 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { getCurrentInstance } from 'vue'

const bus = new Vue()

Vue.mixin({
props : ["value"],
})


Vue.directive('models', {
update: function(el, binding, vnode){
Expand All @@ -26,15 +30,10 @@ export function defineModel<T>(modelValue : string = 'input') : Ref<T>{
__internalValue.value = __instance.$attrs.value as T

setTimeout(() => {
const parentRefs = Object.getOwnPropertyNames(__instance.$parent._setupState).filter((name) => {
return __instance.$parent._setupState[name].dep
watch(__instance.$props, () => {
__internalValue.value = __instance.$props.value as T
})

parentRefs.forEach(ref => { 
watch(__instance.$parent._setupState[ref], () => {
__internalValue.value = __instance.$attrs.value as T
})
})
})
}
else {
Expand Down
Loading

0 comments on commit 7d65892

Please sign in to comment.