Skip to content

Commit

Permalink
fix: dispatch event in go-loop in order to always receive the latest …
Browse files Browse the repository at this point in the history
…evaled message
  • Loading branch information
dviramontes committed Dec 8, 2017
1 parent 3b0fa4d commit bb071a5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/klipse/klipse_editors.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@
(swap! state update-in [:eval-counter] inc)
(let [evaluation-chan (eval-fn (str preamble src-code) @state)
first-result (<! evaluation-chan)]
(let [custom-event (js/CustomEvent. "klipse-snippet-evaled"
(clj->js {:detail {:state (clj->js @state)
:src-code src-code}}))]
(when-let [code-mirror-dom-node (js/document.querySelector ".klipse-container")]
(-> code-mirror-dom-node (.dispatchEvent custom-event))))
(setter first-result)
(when loop-msec
(go-loop []
Expand All @@ -68,6 +63,14 @@
(recur)))))

(go-loop [previous-results first-result]
(when-let [klipse-dom-node (js/document.querySelector ".klipse-container")]
(let [event-payload
(cond
(string? first-result) (clj->js {:detail {:state previous-results}})
(vector? first-result) (clj->js {:detail {:state (clj->js previous-results)}})
:else (clj->js {:detail {:state previous-results}}))]
(-> klipse-dom-node
(.dispatchEvent (js/CustomEvent. "klipse-snippet-evaled" event-payload)))))
(let [result (<! evaluation-chan)
results (str previous-results result)]
(when (some? result) ;exit if the channel is closed
Expand Down

0 comments on commit bb071a5

Please sign in to comment.