ember.js - Re-compute an Ember object's property every interval -
currently have simple ember object, has 2 properties: startedat
, endedat
.
based on these properties, have computed property islive
. time comparison current time.
when rendering handlebar template highlight items adding class highlight
.
<li {{ bindattr class="event.islive:highlight" }}>...</li>
i'd update template every 5 seconds or so, know islive
needs re-calculated. how need go that?
app.event = ember.object.extend({ endedat: null, startedat: null, islive: function() { if (!this.get('startedat') || !this.get('endedat')) { return false; } var = moment(); return (now.diff(moment(this.get('startedat'))) >= 0 && now.diff(moment(this.get('endedat'))) < 0); }.property('startedat', 'endedat') });
i have done similar regular ember view {{view app.timerview}}
.
app.timerview = ember.view.extend({ tagname: 'time', template: ember.handlebars.compile('{{ view.now }}'), init: function() { this._super(); this.set('now', moment().format('hh:mm:ss')); }, now: null, willinsertelement: function(evt) { var self = this; var intervalid = setinterval( function() { self.set('now', moment().format('hh:mm:ss')); }, 1000); this.set('interval', intervalid); }, willdestroyelement: function(evt) { clearinterval(this.get('interval')); } });
but can't seem apply same logic regular object. point me in right direction please.
i believe i'd need in controller according these guides.
i've used solution presented here: http://livsey.org/blog/2013/02/20/tick-tock/
to continuously check on passage of time vs timestamp.
you create clock object , initializer described in post, , create islive property:
.property("startedat", "endedat", "clock.minute") });
using clock.minute fire update every minute. use clock.second if time sensitive (or speed development.