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

Feature/destroy scope #2733

Merged
merged 2 commits into from Mar 7, 2022
Merged

Conversation

SimoTod
Copy link
Collaborator

@SimoTod SimoTod commented Mar 5, 2022

This is not properly a bug but a lot of people are expecting to have access to the current scope in the destroy callback, similarly to what happens in init so they can do stuff like

<div x-data="{
  foo: null,
  init() {foo = setInterval(() => console.log('tick'), 1000)},
  destroy() {clearInterval(foo)}
}">

Note, there are workarounds such as storing data on the global object or inside the function scope when using Alpine.data but they are not obvious ones.

The feature is undocumented so I don't think it's a bug but more of a nicety. Feel free to close it if you think it's not important or there is a specific design choice behind it.

Failing test applied to the current build: https://github.com/SimoTod/alpine/runs/5433954162?check_suite_focus=true#step:6:273

@calebporzio
Copy link
Collaborator

This makes total sense - thanks @SimoTod!

@calebporzio calebporzio merged commit 953d85f into alpinejs:main Mar 7, 2022
AugustMiller added a commit to AugustMiller/alpine that referenced this pull request Mar 7, 2022
Split up the two new sections, and used each to show a more appropriate example, now that `destroy()` has access to component state!
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.

None yet

2 participants