         else
           spawn event
     composite.unsubscribe
-  extraDeps = []
-  result.internalDeps = ->
-    extraDeps.concat(root)
+  result.internalDeps = -> deps
   result
-
 
 class EventStream extends Observable
   constructor: (desc, subscribe) ->

      f()
  findIndependent = ->
    while (!independent(waiters[0]))
      waiters.push(_.popHead(waiters))
    return _.popHead(waiters)

  flush = ->
    while waiters.length

Observable :: assign = Observable :: onValue

flatMap_ = (root, f, firstOnly, limit) ->
  deps = [root]
  result = new EventStream describe(root, "flatMap" + (if firstOnly then "First" else ""), f), (sink) ->
    composite = new CompositeUnsubscribe()
    queue = []
    spawn = (event) ->
      child = makeObservable(f event.value())
      deps.push(child)
      UpdateBarrier.flushDepCache()
      composite.add (unsubAll, unsubMe) -> child.subscribeInternal (event) ->
        if event.isEnd()
          _.remove(child, deps)
          UpdateBarrier.flushDepCache()
          checkQueue()
          checkEnd(unsubMe)
