Skip to content

Instantly share code, notes, and snippets.

@panayi
Created August 31, 2013 09:13
Show Gist options
  • Select an option

  • Save panayi/6397114 to your computer and use it in GitHub Desktop.

Select an option

Save panayi/6397114 to your computer and use it in GitHub Desktop.
Continuous Redrawing of Ember.js Views
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Continuous Redrawing of Views" />
<script src="http://code.jquery.com/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.js"></script>
<script src="http://builds.emberjs.com/ember-latest.js"></script>
<meta charset=utf-8 />
<title>Continuous Redrawing of Views</title>
</head>
<body>
<script type="text/x-handlebars">
{{refresh secondsViewed}}
</script>
</body>
</html>
//
// Handlebars `refresh` helper
//
Ember.Handlebars.registerHelper('refresh', function(property, options) {
var every = options.hash.every || 500;
setInterval(function() {
this.notifyPropertyChange(property);
}.bind(this), every);
return Ember.Handlebars.helpers.bind.call(this, property, options);
});
//
// Example
//
App = Ember.Application.create();
App.ApplicationController = Ember.Controller.extend({
setStart: function() {
this.startSeconds = (new Date()).getTime();
}.on('init'),
secondsViewed: function() {
return ((new Date()).getTime() - this.startSeconds)/1000;
}.property()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment