Created
August 31, 2013 09:13
-
-
Save panayi/6397114 to your computer and use it in GitHub Desktop.
Continuous Redrawing of Ember.js Views
This file contains hidden or 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
| <!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> |
This file contains hidden or 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
| // | |
| // 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