Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: send custom event with code eval state payload #296

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/klipse/klipse_editors.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns klipse.klipse-editors
(:require-macros
[gadjett.core :refer [dbg]]
[purnam.core :refer [!]]
[purnam.core :refer [! !>]]
[cljs.core.async.macros :refer [go go-loop]])
(:require
[goog.dom :as gdom]
Expand Down Expand Up @@ -65,7 +65,16 @@
(let [result (<! evaluation-chan)
results (str previous-results result)]
(when (some? result) ;exit if the channel is closed
(setter results)
(if (string? result)
(setter results)
(let [hasError (and (= (first result) :err))]
(when hasError (setter (second result))) ;; only report the :err messages for now
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to call setter even when there is no error.
The reason is that when the code evaluation succeeds, we pass [:ok res]

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise everything looks fine

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @viebel the problem with setting (setter (second result)) here when there is no error is that the receiver throws
screen shot 2018-02-15 at 7 46 06 pm

I think is is because the message passed in from
klipse/lang/python.cljs:33

(put! c [:ok mod])

puts something on that channel that cannot be stringified.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if that makes sense.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have to call str before putting on the channel.

(put! c [:ok (str mod)])

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense but let me show you what im running into now, it might make more sense to you..
feb-15-2018 23-18-01

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^That's with (put! c [:ok (str mod)]). So its not longer throwing an error but we no longer get the output.

(when-let [klipse-dom-node (js/document.querySelector ".klipse-container")]
(let [event-payload (clj->js {:detail {:result result
:hasError hasError
:resultElement (:result-element @state)}})]
(!> klipse-dom-node.dispatchEvent
(js/CustomEvent. "klipse-snippet-evaled" event-payload))))))
(recur results))))))
(catch :default e
(setter e))))))
Expand Down Expand Up @@ -102,7 +111,7 @@
(s/def ::codemirror-options map?)
(s/def ::editor-mode string?)

(s/fdef editor-options
(s/fdef editor-options
:args (s/cat :in-mode ::editor-mode
:out-mode ::editor-mode
:options-in ::codemirror-options
Expand Down
8 changes: 4 additions & 4 deletions src/klipse/lang/python.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
(init)
(let [c (chan)]
(!> js/Sk.configure #js {:output #(put! c %)
:read builtin-read })
(->
:read builtin-read})
(->
(!> js/Sk.misceval.asyncToPromise
(fn []
(put! c "Output:\n")
(! js/Sk.TurtleGraphics.target container-id)
(!> js/Sk.importMainWithBody "<stdin>" false exp true)))
(.then (fn [mod]
(!> js/console.info "success to eval skulpt: "))
(put! c [:ok mod]))
(fn [err]
(put! c (str "error: " err)))))
(put! c [:err (str "error:\n" err)]))))
c))

(def opts {:editor-in-mode "python"
Expand Down