Init function without x-init #752
skeemer
started this conversation in
4. General
Replies: 2 comments 2 replies
-
It is on the V3 roadmap:
|
Beta Was this translation helpful? Give feedback.
1 reply
-
You could write your own js script to add an auto init: Array.from(document.querySelectorAll('[x-data]')).forEach(alpine => {
alpine.setAttribute('x-init',
[
alpine.getAttribute('x-init'),
`typeof init == 'function' && init()`
].filter(Boolean).join(';')
)
}) then <data x-data="{ something: true, init() { this.something = false } }"></div> |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It would be nice to not have to call x-init directly. I've seen discussions about this and even some about .component(), but that depends on calling the function a specific name from what I've seen. I'm wondering if this would be a good strategy without having to extend the API much. What if when the return from a component function is an array, the first element is the scope and the second is the init function.
Beta Was this translation helpful? Give feedback.
All reactions