I'm bit outdated Ember user, but I would do it like this hope there is a better solution.
App.CurrentTimeView = Ember.View.extend({
template : Ember.Handlebars.compile("<span>{{view.currentTime}}</span>"),
currentTime : null,
init : function(){
var view = this;
view.set('currentTime', moment().format('h:mm:ss a'));
setInterval((function(view){
return function(){view.set('currentTime', moment().format('h:mm:ss a'));};
})(view),1000);
}
});
and in the template
{{view "App.CurrentTimeView"}}
To answer your question,
Javascript has a single threaded execution (unless you use webworkers) which means it will do things one by one in a serial manner. When you use setInterval
it will en-queue your function every x
milliseconds into this main execution queue. setInterval
uses the passed time
to do its queuing.
Ember run loops will kind of calculate bindings and other heavy things in each run loop, so at the end of the loop we are sure that out changes are there ready. There are hooks like Em.run.next to make sure those codes when being run will have the complete changes done in last run loop. Similarly when you pass a time to Em.run.later it will as well run after that much time and also supports a parameter to set this
inside the function. Mostly when dealing with some variables or Model/Controller data inside the function.
In your case setInterval looks ok (for me).
http://jsfiddle.net/NQKvy/604/