Useful Pattern for Emberjs to refresh client session
App.RefreshSession = (controller, cb) ->
#do what you need here to refresh the session.. reading cookie etc
App.ServerProxy = (controller, cb) ->
if App.CurrentSession?
cb()
else
App.RefreshSession(controller,cb)
Call App.ServerProxy for all your server calls
Then in Ember return a promise to ensure things get synced especially if App.RefreshSession
goes off to fetch stuff from the server so:
App = Em.Application.create();
App.SomeRoute = Em.Route.extend({
model: function(){
return new RSVP.Promise(function(resolve, reject){
App.ServerProxy(function(){....});
});
}
});
Written by charlie
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Emberjs
Authors
Related Tags
#emberjs
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#