clojure.browser.repl/start-evaluator

functionsince v0.0-927Edit
(start-evaluator url)

Source docstring:
Start the REPL server connection process. This process runs inside the
embedded iframe.
Source code @ clojurescript:src/main/cljs/clojure/browser/repl.cljs
(defn start-evaluator
  [url]
  (if-let [repl-connection (net/xpc-connection)]
    (let [connection (net/xhr-connection)
          repl-connected? (atom false)
          try-handshake (fn try-handshake []
                          (when-not @repl-connected?
                            (net/transmit repl-connection :start-handshake nil)))]
      (net/connect repl-connection try-handshake)

      (net/register-service repl-connection
        :ack-handshake
        (fn [_]
          (when-not @repl-connected?
            (reset! repl-connected? true)
            ;; Now that we're connected to the parent, we can start talking to
            ;; the server.
            (send-result connection
              url (wrap-message nil :ready "ready")))))

      (event/listen connection
        :error
        (fn [e]
          (reset! repl-connected? false)
          (net/transmit repl-connection :reconnect nil)
          (js/setTimeout try-handshake 1000)))

      (event/listen connection
        :success
        (fn [e]
          (net/transmit
            repl-connection
            :evaluate-javascript
            (.getResponseText (.-currentTarget e) ()))))

      (net/register-service repl-connection
        :send-result
        (fn [json]
          (let [obj    (json/parse json)
                repl   (gobj/get obj "repl")
                result (gobj/get obj "result")]
            (send-result connection url
              (wrap-message repl :result result)))))

      (net/register-service repl-connection
        :print
        (fn [json]
          (let [obj  (json/parse json)
                repl (gobj/get obj "repl")
                str  (gobj/get obj "str")]
            (send-print url (wrap-message repl :print str))))))
    (js/alert "No 'xpc' param provided to child iframe.")))