Skip to content

Instantly share code, notes, and snippets.

@H1D
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save H1D/37629132f15dd23ade69 to your computer and use it in GitHub Desktop.
Save H1D/37629132f15dd23ade69 to your computer and use it in GitHub Desktop.
Silently updating Ember-app on client side
`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')
@MiguelMadero
Copy link

The name seems confusing since the willTransition function is executed on didTransition not on willTransition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment