gsklee / ngStorage

localStorage and sessionStorage done right for AngularJS.
MIT License
2.33k stars 461 forks source link

Update webStorage on route change, rather then manual intervention #197

Open sime opened 8 years ago

sime commented 8 years ago

Currently if a storage modification is done followed by a route change, it is possible that the changes haven't been committed and thus not available. This PR is the Angular equivalent to the beforeunload listener.

Rather than making the user manually specify a $timeout() prior to a route change, I think it is of greater convenience to execute $storage.$apply() on $routeChangeStart/$stateChangeStart.

If this may be a undesirable default behaviour, a configuration option can easily be set up.

schmuli commented 7 years ago

Wouldn't it be more correct to just listen to the $locationChangeStart event, from the Location service?

sime commented 7 years ago

@schmuli I can't recall my reasoning, but I feel I recall waiting for $locationChangeStart to fire in ui-router and it never happening.