   constructor: (f, @_parent, p)->
     if p != privateObj
       throw new Error("Tracker.Computation constructor is private; use Tracker.autorun")
-    
+
     @stopped = false
     @invalidated = false
     @firstRun = true
     @_id = nextId++
     @_onInvalidateCallbacks = []
     @_recomputing = false
-    
+
     Tracker.currentComputationVar.withValue @, =>
       @_func = Meteor.bindEnvironment(f, null, @)
-    
+
     errored = true
     try
       @._compute()

      catch e
        console.log e
    @_recomputing = false
    
class Tracker.Dependency
  constructor: ->
    @_dependentsById = {}
  
  depend: (computation = Tracker.currentComputation) ->
    if not computation
      return false
    
    id = computation._id
    
    if not (id of @_dependentsById)
      @_dependentsById[id] = computation
      computation.onInvalidate =>
        delete @_dependentsById[id]
      
      return true
    false
    
  changed: ->
    for id, computation of @_dependentsById
      computation.invalidate()
    
  hasDependents: ->
    for id, computation of @_dependentsById
      return true
    false
    


_.extend Tracker,
  currentComputationVar: new Meteor.EnvironmentVariable()

  flush: ->
    if not queue.safeToRunTask()
      throw new Error("Can't call Tracker.flush while flushing, or inside Tracker.autorun")

    queue.drain()

  _postRun: ->
    while (queue._taskHandles.length == 0) and (afterFlushCallbacks.length > 0)
      f = afterFlushCallbacks.shift()
