I am using PubNub as a socket service and would like to update the content when the user reconnects or connects for the first time.
We will be using local storage to store some basic info about the user, this will include an active_auction
property that is used to say get items
return this.store.query('item',{auction_id: this.get('localStorage').getItem('user').active_auction})
Currently the user gets set in local storage by visiting the index
route with a short_url
as the dynamic segment. All that works, however the user could change their active_auction
outside of the system, and when they open the system back up rather than forcing them to put their short url in each time to update the information and therefore get the new active_auction
we want to get the users info in the background upon connecting to the app again and thusly update any information on the page.
Currently I'm using a service someone put together using PubNub's own ember library. This allows me to listen on reconnect
events and do things, here I am attempting to go out and get the user information again...
return self.store.findRecord('user',self.get('localStorage.user.user_url')).then(function(result){
if(result){
// set user data in local storage
self.get('localStorage').setItem('user', {
...
});
self.send('reconnect');
}
});
Then the active route can catch the reconnect
action and reload it's data. So far this all works, but only the first reconnect. If I turn the wifi off, change active events through our other system, and then turn the wifi back on, it reconnects, gets the users data, which sees the new active_auction
and the items
route that is active fires it's action to reload the data and all works fine. However, without refreshing, if I do this process again, the second time or even third time to not see the updated active_auction
and data is not being refreshed to reflect the active_auction
change.
Is there something I can do to make sure this always happens? It seems like maybe ember is doing something to save network calls that is preventing it from getting the new data each time and not just on the first time.
Aucun commentaire:
Enregistrer un commentaire