jondot / graphene

Graphene is a realtime dashboard & graphing toolkit based on D3 and Backbone.
http://jondot.github.com/graphene
2.87k stars 232 forks source link

How to stop graphene object and backbone http calls, and refresh. #51

Closed paulinhoAlmeida closed 11 years ago

paulinhoAlmeida commented 11 years ago

How can I stop graphene object and backbone http calls and is refresh, The situation is this one, I'm trying to Graphene into a Jquery UI so when I go from one Div to another, I want to stop the ajax calls.

paulinhoAlmeida commented 11 years ago

I came out with this solution let me know if is a good one

listOfTs = []

build: (json)=> .each .keys(json), (k)=> console.log "building [#{k}]" if @is_demo klass = Graphene.DemoTimeSeries else klass = Graphene.TimeSeries

  model_opts = {source: json[k].source}
  delete json[k].source
  if json[k].refresh_interval
    model_opts.refresh_interval = json[k].refresh_interval
    delete json[k].refresh_interval
  ts = new klass(model_opts)

  _.each json[k], (opts, view)=>
    klass = eval("Graphene.#{view}View")
    console.log _.extend({ model: ts, ymin:@getUrlParam(model_opts.source, "yMin"), ymax:@getUrlParam(model_opts.source, "yMax") }, opts)
    new klass(_.extend({ model: ts, ymin:@getUrlParam(model_opts.source, "yMin"), ymax:@getUrlParam(model_opts.source, "yMax") }, opts))
    listOfTs.push(ts)
    ts.start()

stop:-> _.each listOfTs, (ts, index)-> ts.stop();

jondot commented 11 years ago

Yes, this is what stop was for, your solution is good.