jondot/graphene

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

paulinhoAlmeida opened this issue · 2 comments

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.

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();

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