Skip to content

Commit

Permalink
feat(directive): unref initial binding (supports refs in object)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tahul committed Apr 2, 2022
1 parent a996c9d commit b84a42b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/directive/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Directive, DirectiveBinding, VNode } from 'vue-demi'
import defu from 'defu'
import { set as __set, ref } from 'vue-demi'
import { set as __set, ref, unref } from 'vue-demi'
import { motionState } from '../features/state'
import type { MotionVariants } from '../types'
import { useMotion } from '../useMotion'
Expand Down Expand Up @@ -57,14 +57,16 @@ export const directive = (
created: register,
unmounted: unregister,
// Vue 2 Directive Hooks
// For Nuxt & Vue 2 compatibility
// For Nuxt & Vue 2 Compatibility
// @ts-expect-error - Compatibility
bind: register,
unbind: unregister,
// Vue 3 SSR
getSSRProps(binding, el) {
getSSRProps(binding, node) {
// Get initial value from binding
const { initial: bindingInitial } = binding.value || (el && el.props) || {}
let { initial: bindingInitial } = binding.value || (node && node.props) || {}

bindingInitial = unref(bindingInitial)

// Merge it with directive initial variants
const initial = defu(variants?.initial || {}, bindingInitial || {})
Expand Down

0 comments on commit b84a42b

Please sign in to comment.