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

$parent use within <template> tags? #1

Closed
njpanderson opened this issue Dec 27, 2022 · 1 comment
Closed

$parent use within <template> tags? #1

njpanderson opened this issue Dec 27, 2022 · 1 comment

Comments

@njpanderson
Copy link

Hi there — firstly, thanks for the great plugin, it mostly seems to work brilliantly. One bit of oddness I've just discovered though: When I use $parent in a template element within a child component, it seems to refer to the current component, unless I do $parent.$parent.xyz. I'd tested with the following markup

https://jsfiddle.net/njpanderson/wbLf9krv/19/

If I use unique names for the properties, they work as expected, although that seems to defeat the purpose.

Is this expected behaviour? If so, all good — I can confidently use $parent.$parent and understand that it won't regress in a future minor version. It would be nice to have a note in the docs though, if that is the case. If not, then do you know what might be wrong?

Thanks again!

@ryangjchandler
Copy link
Owner

I think this is a side effect of how Alpine is storing data for each "node" inside of the x-for. The under-the-hood logic is essentially treating each element produced by the x-for as a separate Alpine component, storing the iteration variables as the data, so yes. Unless Alpine.js changes how it is doing this, $parent.$parent will be reliable.

If I need to change it for whatever reason such that it breaks, a new major release will be needed anyway.

@ryangjchandler ryangjchandler closed this as not planned Won't fix, can't repro, duplicate, stale Dec 27, 2022
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

No branches or pull requests

2 participants