-
-
Save H1D/37629132f15dd23ade69 to your computer and use it in GitHub Desktop.
Silently updating Ember-app on client side
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`import 'ember'` | |
# this is an first raw attemp on "silent ember app updates" | |
# more info -- http://discuss.emberjs.com/t/best-practices-for-updating-ember-app-on-client/6502 | |
versionMonitor = Em.Object.create | |
current_version: null | |
availabe_version: null | |
### | |
trick is to update availabe_version somehow (websokets/long-poll ...) | |
### | |
is_update_needed: (-> | |
if @get('current_version.hash') | |
if @get('current_version.hash') != @get('availabe_version.hash') | |
return true | |
).property('current_version', 'availabe_version') | |
Ember.Application.initializer | |
after: "store" | |
name: 'silent-updater' | |
initialize: (container, application) -> | |
versionMonitor | |
# set current version | |
versionMonitor.set 'versionMonitor', {hash: 'XXX'} | |
# listening for router transitions | |
application.Router.reopen | |
willTransition: (-> | |
if versionMonitor.get('is_update_needed') | |
window.location.reload() | |
).on('didTransition') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The name seems confusing since the willTransition function is executed on
didTransition
not on willTransition