Tuesday, August 26, 2014

How to Detect Back Button Event

I've been using a HistoryStack implementation attached to History.addValueChangeListener() in my app. This works well, but it's not truly a "stack" of Places.

If it were a true history stack, when a user hit back, then I'd pop off that Place and it would no longer be on the stack. However, History.addValueChangeListener() does not tell us whether the user went back, only the string of the Place that is now loaded. We could simply match this to the N-1 entry on the stack and remove the N (top) entry if they matched, but this makes assumptions.


As designed, we cannot differentiate between the following two user flows:

1. Place A -> (click link) Place B -> (link clicked) Place A
2. Place A-> (click link) Place B -> (back button) Place A

So the user could have made a cycle in our Place graph, or they could have just hit back. In the first case the stack would be [A,B,A] in the second case it should be [A].

I've also looked at the Window.onpopstate event, but the object returned only shows the new state, not the transition that got us there. Since it's triggered by Back AND Forward actions, you don't know which it was. It seems wrongly named as Forward is not popping off the history state stack, unless you consider the forward stack as being reduced, but then every action is a pop and a concomitant push.


So, how do other GWT'er determine when a user clicks the back button? Thanks.


Sincerely,
Joseph

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment