Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Template - Run generic JS onMounted #1186

Merged
merged 3 commits into from
Aug 9, 2024
Merged

UI Template - Run generic JS onMounted #1186

merged 3 commits into from
Aug 9, 2024

Conversation

joepavitt
Copy link
Collaborator

@joepavitt joepavitt commented Aug 8, 2024

Description

  • We group any generic JS we find into a beforeCreate function, which was then run in the beforeCreate lifecycle hook of VueJS. This was causing problems though if a user was trying to reference HTML elements in their component e.g. https://discourse.nodered.org/t/graph-shapes-and-single-point/90041/4 as the component hadn't yet been mounted.
  • This PR moves the beforeCreate content (i.e. generic JS) into a new hok called js, and runs this code in mounted() instead so that the code can reference HTML content

@joepavitt joepavitt requested a review from Steve-Mcl August 8, 2024 17:29
Copy link
Contributor

@Steve-Mcl Steve-Mcl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with an optional comment update.

One (probably naive) question though, why mounted and not beforeMount?

would beforeMount not give users an opportunity to "do stuff" before its displayed? (or would it simply not work due to not being present in the DOM)?

ui/src/util/vue.acorn.js Outdated Show resolved Hide resolved
Co-authored-by: Stephen McLaughlin <[email protected]>
@joepavitt
Copy link
Collaborator Author

(or would it simply not work due to not being present in the DOM)?

This - beforeMount would still not permit code to reference elements in the DOM

@Steve-Mcl Steve-Mcl merged commit fff158d into main Aug 9, 2024
1 of 2 checks passed
@Steve-Mcl Steve-Mcl deleted the ui-template-mounted branch August 9, 2024 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants