0

I am still rather new to Ember and I am stuck on an idea that I would like to get done. I could do this in JQuery/Javascript, but I want to use some of the Ember features to get this properly done.

I am trying to create a live stock ticker, that would simply auto-refresh every few seconds with a value +50, -100, +1512, -25, etc.

I am mostly just stuck on how to get a variable that auto-refreshes per the allotted amount of time. Should I create a custom component?

Any tips would be appreciated, thanks

UPDATE:

<span class="pull-right">Ember Stock Market: {{emberStock}} </span>

App.ApplicationController = Ember.Controller.extend({   
    emberStock: '0'
});

App.ApplicationRoute = Ember.Route.extend({
    setupController: function(controller){
            this.stockTicker(controller);
    },
    stockTicker: function(controller){
        var self = this;
        var price = Math.floor(Math.random() * 50) - 1;

        controller.set('emberStock', price);

        Em.run.later(function(){
            self.stockTicker(controller);
        }, 1000);
    }
});
  • This question should help: [How to update Ember's model periodically (such as in setInterval)?]: http://stackoverflow.com/questions/21708931/how-to-update-embers-model-periodically-such-as-in-setinterval – datchung May 05 '15 at 01:38
  • Thanks for the tip I think I got it now. – Chris Stephens May 05 '15 at 03:55
  • you should also consider sockets for this http://pixelhandler.com/posts/real-time-data-in-an-emberjs-application-with-websockets –  May 05 '15 at 08:42
  • And you should consider to have the `stockTicker` function in the Controller, not the Route. – Lux May 05 '15 at 13:34

1 Answers1

0

If you don't want to re-invent the wheel, you might want to use ember-cli-clock.

jnfingerle
  • 713
  • 4
  • 16