From bb071a59584a123d85a1eac301cbbed4a9017843 Mon Sep 17 00:00:00 2001 From: David Viramontes Date: Thu, 7 Dec 2017 20:11:04 -0700 Subject: [PATCH] fix: dispatch event in go-loop in order to always receive the latest evaled message --- src/klipse/klipse_editors.cljs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/klipse/klipse_editors.cljs b/src/klipse/klipse_editors.cljs index 38ffe0fa..3c608eb8 100644 --- a/src/klipse/klipse_editors.cljs +++ b/src/klipse/klipse_editors.cljs @@ -52,11 +52,6 @@ (swap! state update-in [:eval-counter] inc) (let [evaluation-chan (eval-fn (str preamble src-code) @state) first-result (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 [] @@ -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 (