Giter Club home page Giter Club logo

Comments (12)

jasonmit avatar jasonmit commented on June 19, 2024 1

So I think that either README should state that one needs to make sure any code within onUnload needs to be blocking or that onUpdate is changed so that it would be onUnload(resolve, reject) to help people get correct behavior.

Likely the README update. The latter would be confusing since window.onunload won't allow anything async to run in full (AFAIK). onUnload is meant for when the application is going to be torn down, not to be fired between routes.

But you raise an interesting point, perhaps we need a hook for handling transitions as well. So transitions between routes could be async, but a transitions away from the app needs to be sync.

I think a new hook should be introduced for onRouteUnload vs onAppUnload.

from ember-onbeforeunload.

blimmer avatar blimmer commented on June 19, 2024

Thanks for reporting this @matthewvalimaki - can you throw together a quick twiddle that shows this behavior for us?

here's a twiddle with the addon pre-installed:

https://ember-twiddle.com/af013400c74fc407a45e74327ed9f9cb

thank you!

from ember-onbeforeunload.

matthewvalimaki avatar matthewvalimaki commented on June 19, 2024

@blimmer done, see https://ember-twiddle.com/e4683bc6bd03a0a01698886ed7daa002.

from ember-onbeforeunload.

matthewvalimaki avatar matthewvalimaki commented on June 19, 2024

Just a bit off-topic but related to onUnload execution and the fix I am proposing. In my use case when user says "yes" I need to revert bunch of database changes and only after that transition. Problem is that onUnload by default does not use Promise and so asynchronous things become somewhat problematic.

So I think that either README should state that one needs to make sure any code within onUnload needs to be blocking or that onUpdate is changed so that it would be onUnload(resolve, reject) to help people get correct behavior.

If we were to change to onUpdate(resolve, reject) then the first thing would be to transition.abort(), call onUnload and then transition.retry().

from ember-onbeforeunload.

matthewvalimaki avatar matthewvalimaki commented on June 19, 2024

Forgot to mention that transition should be given to onUnload in case there's further logic I want to do. Also it might be a good idea to hand the model like with others as well. While I can get it myself from transition it would be code replication vs. having it supplied.

from ember-onbeforeunload.

matthewvalimaki avatar matthewvalimaki commented on June 19, 2024

The way I understood README was that this was for route transitions as well, so I would prefer your suggestion to introduce new hooks to clarify intent.

from ember-onbeforeunload.

dja avatar dja commented on June 19, 2024

@jasonmit Do you think you'll be able to add onRouteUnload easily? or do you need help?

from ember-onbeforeunload.

jasonmit avatar jasonmit commented on June 19, 2024

@dja pretty easy. The logic is in place, just need to split the onUnload hook up into two hooks and call the correct respective hook depending on what occurred. As for help, would love the help :)

from ember-onbeforeunload.

 avatar commented on June 19, 2024

Hi! I wanted to see if this fix was planning on being implemented anytime soon? It seems like that PR above would work for my use case.

from ember-onbeforeunload.

tylerturdenpants avatar tylerturdenpants commented on June 19, 2024

@devups lets get the PR green and Iโ€™ll cut a beta. I need to analyze if this is a breaking change. I think this behavior could also be configured so that itโ€™s an opt in instead of all or nothing. How does that sound?

from ember-onbeforeunload.

 avatar commented on June 19, 2024

@tylerturdenpants Yeah, that sounds awesome. Ty!

from ember-onbeforeunload.

tylerturdenpants avatar tylerturdenpants commented on June 19, 2024

@devups Do you mind taking over the PR work? Iโ€™m simply too busy.

from ember-onbeforeunload.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.