X-init execution of first declared function only #4416
Unanswered
maxkokocom
asked this question in
5. Bugs
Replies: 2 comments 1 reply
-
You don't call any functions here. But also, why are these being defined in x init? And not just in a script tag? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Functions, in alpine directives, gets autocalled (by design). As mentioned above, the right place to define a function for your component is x-data (or Alpine.data depending on what you use). |
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
-
Hi, not sure is it a bug, feature or discussion. It was a bug for me, but I found very random solution which should maybe be documentated or explained somehow. I was doing toasts and had an issue of empty toast showing up on every single refresh. I was not able to create function which would not execute without loosing ability to call this function later on. To my suprise simply declaring other function in front of it in x-init solved it.
Adding
myGlobalFunction
makes it execute, but the next function is not executed anymore, but still works from global scope when called by other scripts. I wonder what should be correct way of making it work... This seems very random and I found it out by accident. Let me know what is the recommanded way to create callable functions which are in global scope, but are not executed. I am new to alpine.js maybe I am missing obvious, but I was trying different vanila js callback functions and nothing work, except for adding other function in first position.Beta Was this translation helpful? Give feedback.
All reactions