This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-02
Channels
- # announcements (9)
- # babashka (67)
- # beginners (62)
- # bitcoin (2)
- # clara (1)
- # clj-kondo (62)
- # cljfx (6)
- # cljs-dev (25)
- # clojars (17)
- # clojure (142)
- # clojure-australia (2)
- # clojure-europe (42)
- # clojure-gamedev (2)
- # clojure-nl (31)
- # clojure-poland (10)
- # clojure-spec (14)
- # clojure-uk (30)
- # clojurescript (3)
- # conjure (1)
- # cursive (10)
- # data-science (1)
- # datascript (4)
- # datomic (9)
- # depstar (7)
- # fulcro (17)
- # girouette (15)
- # graalvm (44)
- # honeysql (20)
- # jackdaw (3)
- # jobs (8)
- # jobs-discuss (10)
- # juxt (5)
- # lein-figwheel (1)
- # lsp (175)
- # malli (19)
- # pedestal (2)
- # reagent (31)
- # reitit (2)
- # remote-jobs (3)
- # reveal (12)
- # sci (77)
- # shadow-cljs (22)
- # specter (6)
- # startup-in-a-month (2)
- # tools-deps (1)
- # xtdb (21)
I’m experimenting with self-hosted cljs in the browser, bootstrapped with shadow-cljs. I’m evaluating cljs typed into a textarea, eval’ed with the on-change event (debounced by a few hundred milliseconds). It works fine mostly, however, I’ve noticed that when typing in forms/expressions that yield infinite lazy sequences, the browser seizes up and stops responding. For example, typing (range)
causes this behavior. Are there any good strategies for dealing with this?
I use cljs/eval-str
and show the result in a div
The problem I have is that I can’t prevent users of the web-app from evaluating infinite series that they’ve input into the textarea…
Is there a way to force-kill the infinite evaluation? (like hitting Ctrl-C when hitting an infinite loop in a command-line REPL?)
well HOW do you display it in a div? I assume pr-str
? THAT is were your infinite sequence is realized
No, I simply do this:
(defonce evaluated-output (r/atom nil))
(defn compile-it [code]
(let [options {:eval cljs/js-eval
:load (partial boot/load c-state)}
callback (fn [result]
(reset! evaluated-output (:value result)))]
(cljs/eval-str c-state code "[demo-bootstrap-cljs]" options callback)))
and then I render it:
[:pre>code "Output: " [:strong (str @evaluated-output)]]
Yes, I see what you’re saying now
I’m not clear what the difference it, but I will put pr-str
then
That works perfectly! You’re awesome, @U05224H0W Thanks so much!!!