Detect when document is popped from stack

Use case:

- User requests a template.

- Using the standard Apple boilerplate code, a loadingIndicator is added to the navigationDocument while the template loads.

- Let's say there's a long-running background process and the user doesn't want to wait.

- User hits back on the remote while the loadingIndicator is showing, before the new template is pushed to the stack.


Problem:

- Presenter.js: this.loadingIndicatorVisible is not reset to false, causing an error whenever trying to add something else to the stack in future.


Question:

- How can I detect whether a document has been removed, or has been popped from the navigation stack?

- I'd like to use this as an opportunity to reset the loadingIndicatorVisible value, but also to do any cleanup / cancel network requests etc.


I'm aware that it's possible to manually pop/remove a document from the stack, but am looking for a catch-all way to detect this event.


Any ideas much appreciated, thanks!

You can add an event listener for 'load', 'appear', 'disappear' and 'unload' events on a document to monitor document lifecycles.


For example, in your case, you could do this:

loadingTemplate.addEventListener('unload', function(event) { if (stillLoading) { // reset flags } }, false);

Detect when document is popped from stack
 
 
Q