Skip to content

Commit 33baa7a

Browse files
committed
✨ (useMotions) return global state on useMotions
1 parent 1e4e509 commit 33baa7a

File tree

1 file changed

+2
-26
lines changed

1 file changed

+2
-26
lines changed

src/useMotions.ts

+2-26
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
1-
import { getCurrentInstance, onMounted, shallowReactive } from 'vue'
2-
import { MotionDirectiveInjection } from './plugin'
1+
import { motionState } from './features/state'
32

4-
/**
5-
* A Composable giving access to current component instance `$motions` instances declared via `v-motion` from the template.
6-
*/
73
export function useMotions() {
8-
// Get the current component instance
9-
const app = getCurrentInstance()
10-
11-
// Create a shallow reactive object, holding motions
12-
const motions = shallowReactive<MotionDirectiveInjection>({})
13-
14-
// On mounted, get all the $motions, and bind them to the shallow reactive object
15-
onMounted(() => {
16-
// Check if the current component instance has $motions injected
17-
if (app?.proxy?.$motions) {
18-
// Append the local shallowReactive object with all the $motions injected in the component instance
19-
Object.assign(motions, app.proxy.$motions)
20-
} else {
21-
// If there's no v-motions in the component, this hook shouldn't be present in setup().
22-
console.warn(
23-
`Could not find any motion in this component, are you using v-motion anywhere?`,
24-
)
25-
}
26-
})
27-
28-
return motions
4+
return motionState
295
}

0 commit comments

Comments
 (0)