fix!: v-model implemented again
* fix store usage Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -30,7 +30,7 @@ const color = ref<Colors>({
|
|||||||
blue: 100,
|
blue: 100,
|
||||||
})
|
})
|
||||||
const onChange = ({ color: c, val }: { color: keyof Colors; val: number }) => (color.value[c] = Number(val))
|
const onChange = ({ color: c, val }: { color: keyof Colors; val: number }) => (color.value[c] = Number(val))
|
||||||
const { store } = useVueFlow({
|
const store = useVueFlow({
|
||||||
nodeTypes: {
|
nodeTypes: {
|
||||||
'rgb': true,
|
'rgb': true,
|
||||||
'rgb-output': true,
|
'rgb-output': true,
|
||||||
|
|||||||
@@ -103,7 +103,6 @@ const emit = defineEmits(Object.keys(createHooks()))
|
|||||||
|
|
||||||
const { store, hooks } = initFlow(emit, props)
|
const { store, hooks } = initFlow(emit, props)
|
||||||
const init = (opts: typeof props) => {
|
const init = (opts: typeof props) => {
|
||||||
store.elements = opts.elements
|
|
||||||
for (const opt of Object.keys(opts)) {
|
for (const opt of Object.keys(opts)) {
|
||||||
const val = opts[opt as keyof FlowProps]
|
const val = opts[opt as keyof FlowProps]
|
||||||
if (val && typeof val !== 'undefined') (store.$state as any)[opt] = val
|
if (val && typeof val !== 'undefined') (store.$state as any)[opt] = val
|
||||||
@@ -116,6 +115,18 @@ const init = (opts: typeof props) => {
|
|||||||
}
|
}
|
||||||
onBeforeUnmount(() => store?.$dispose())
|
onBeforeUnmount(() => store?.$dispose())
|
||||||
|
|
||||||
|
const elements = useVModel(props, 'elements', emit)
|
||||||
|
watch(
|
||||||
|
elements,
|
||||||
|
(val, oldVal) => {
|
||||||
|
nextTick(() => {
|
||||||
|
const hasDiff = diff(val, oldVal)
|
||||||
|
if (hasDiff.length > 0) store.setElements(val)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
{ flush: 'post', deep: true },
|
||||||
|
)
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props,
|
() => props,
|
||||||
(val, oldVal) => {
|
(val, oldVal) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user