 
 sync = new DreamSync()
 
-# This will be initialized once the iframe is added to the DOM.
-editor = null
+# This will be initialized once the iframe has been added to the DOM.
+maybeEditor = null
 
 withEditor = (callback) ->
-  if editor?
-    callback editor
+  if maybeEditor?
+    callback maybeEditor
   else
     # If the editor isn't initialized yet, yield and try again until it's ready.
     setTimeout (-> withEditor callback), 0


    doc = {
      title:    inferTitleFrom(wrapperNode) ? ""
      chapters: inferChaptersFrom(wrapperNode)
    }

    sync.saveDocWithSnapshot doc, {html}, (doc, snapshot) ->

}

setUpEditor = (iframe) ->
  maybeEditor = new Editor iframe, mutationObserverOptions, (mutations, node) ->
    sync.getCurrentDocId (currentDocId) ->
      sync.getDoc currentDocId, (doc) ->
        doc.title    = inferTitleFrom(node) ? doc.title ? ""
