 Object.defineProperties Tracker,
   currentComputation:
     get: ->
-      Tracker._currentComputation.get()
+      # We want to make sure we are returning null and not
+      # undefined if there is no current computation.
+      Tracker._currentComputation.get() or null
 
   active:
     get: ->


  nonreactive: (f) ->
    Tracker._currentComputation.withValue null, f

  _makeNonreactive: (f) ->
    if f.$isNonreactive
      return f
    result = (args...) ->
      Tracker.nonreactive =>
        f.apply(@, args)
    result.$isNonreactive = true
    result

  onInvalidate: (f) ->
    throw new Error "Tracker.onInvalidate requires a currentComputation" unless Tracker.active

  onInvalidate: (f) ->
    throw new Error "onInvalidate requires a function" unless typeof f is 'function'

    if @invalidated
      Tracker.nonreactive =>
        f @
    else
      @_onInvalidateCallbacks.push f

