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

Add URLHashDemo w/ window.onhashchange closure #288

Merged
merged 2 commits into from
Oct 6, 2020
Merged

Conversation

MaxDesiatov
Copy link
Collaborator

Resolves #284.

@MaxDesiatov MaxDesiatov added the documentation Technical writing, references, tutorials etc label Oct 6, 2020
@MaxDesiatov MaxDesiatov requested a review from a team October 6, 2020 18:30
@MaxDesiatov
Copy link
Collaborator Author

MaxDesiatov commented Oct 6, 2020

@vi4m please check out the code in this PR. I imagine onpopstate would work similarly. The key bit here is that we need to manage lifetime of closures manually, because JavaScript doesn't have finalizers. Swift code can't be notified when JavaScript references to these closures are deallocated, so everything needs to be cleaned up manually. This is possible thanks to HashState being a reference type with deinit.

@vi4m
Copy link

vi4m commented Oct 6, 2020

Thanks! This code looks really easy on the eyes, and works perfectly.
I'm sure it will enrich documentation / help other early adopters as well 👍

@MaxDesiatov MaxDesiatov merged commit dbd1ee4 into main Oct 6, 2020
@MaxDesiatov MaxDesiatov deleted the hash-change-demo branch October 6, 2020 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Technical writing, references, tutorials etc
Development

Successfully merging this pull request may close these issues.

Pattern for handling global dom events
3 participants