|
31 | 31 | (goog-define HOST "localhost") |
32 | 32 | (goog-define PORT 9000) |
33 | 33 |
|
| 34 | +(def ^:dynamic *repl* nil) |
34 | 35 | (def xpc-connection (atom nil)) |
35 | 36 | (def parent-connected? (atom false)) |
36 | 37 | (def print-queue (array)) |
|
92 | 93 |
|
93 | 94 | (def order (atom 0)) |
94 | 95 |
|
95 | | -(defn wrap-message [t data] |
96 | | - (pr-str {:type t :content data :order (swap! order inc)})) |
| 96 | +(defn wrap-message [repl t data] |
| 97 | + (pr-str |
| 98 | + {:repl repl |
| 99 | + :type t |
| 100 | + :content data |
| 101 | + :order (swap! order inc)})) |
97 | 102 |
|
98 | 103 | (defn start-evaluator |
99 | 104 | "Start the REPL server connection." |
|
110 | 115 | ;; ack once. |
111 | 116 | (js/setTimeout try-handshake |
112 | 117 | 10)))] |
113 | | - (net/connect repl-connection |
114 | | - try-handshake) |
| 118 | + (net/connect repl-connection try-handshake) |
115 | 119 |
|
116 | 120 | (net/register-service repl-connection |
117 | 121 | :ack-handshake |
|
121 | 125 | ;; Now that we're connected to the parent, we can start talking to |
122 | 126 | ;; the server. |
123 | 127 | (send-result connection |
124 | | - url |
125 | | - (wrap-message :ready "ready"))))) |
| 128 | + url (wrap-message nil :ready "ready"))))) |
126 | 129 |
|
127 | 130 | (event/listen connection |
128 | 131 | :success |
129 | 132 | (fn [e] |
130 | 133 | (net/transmit |
131 | 134 | repl-connection |
132 | 135 | :evaluate-javascript |
133 | | - (.getResponseText (.-currentTarget e) |
134 | | - ())))) |
| 136 | + (.getResponseText (.-currentTarget e) ())))) |
135 | 137 |
|
136 | 138 | (net/register-service repl-connection |
137 | 139 | :send-result |
138 | | - (fn [data] |
139 | | - (send-result connection url (wrap-message :result data)))) |
| 140 | + (fn [{:keys [repl result]}] |
| 141 | + (send-result connection url |
| 142 | + (wrap-message repl :result result)))) |
140 | 143 |
|
141 | 144 | (net/register-service repl-connection |
142 | 145 | :print |
143 | 146 | (fn [data] |
144 | | - (send-print url (wrap-message :print data))))) |
| 147 | + (send-print url (wrap-message nil :print data))))) |
145 | 148 | (js/alert "No 'xpc' param provided to child iframe."))) |
146 | 149 |
|
147 | 150 | (def load-queue nil) |
|
234 | 237 | (net/transmit |
235 | 238 | repl-connection |
236 | 239 | :send-result |
237 | | - (evaluate-javascript repl-connection (gobj/get obj "form")))))) |
| 240 | + {:repl (gobj/get obj "repl") |
| 241 | + :result (evaluate-javascript repl-connection |
| 242 | + (gobj/get obj "form"))})))) |
238 | 243 | (net/connect repl-connection |
239 | 244 | (constantly nil) |
240 | 245 | (fn [iframe] |
|
0 commit comments