From 19fe9152e7a0b91b4d6de0f98f6e3e3be6041c95 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sat, 21 May 2022 21:51:42 +0200 Subject: [PATCH] wip [skip ci] --- deps.edn | 3 ++- resources/public/index.html | 12 +++++++++++- src/scittle/core.cljs | 9 +++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/deps.edn b/deps.edn index b86c4e9..72e6cfb 100644 --- a/deps.edn +++ b/deps.edn @@ -3,8 +3,9 @@ :deps {org.clojure/clojure {:mvn/version "1.10.3"} org.babashka/sci #_{:mvn/version "0.3.5"} - {:git/url "https://github.com/babashka/sci" + #_{:git/url "https://github.com/babashka/sci" :git/sha "b95519dc283bebafa3dcce01c3e9eaaa568d0fcb"} + {:local/root "../babashka/sci"} reagent/reagent {:mvn/version "1.1.0"} cljsjs/react {:mvn/version "17.0.2-0"} cljsjs/react-dom {:mvn/version "17.0.2-0"} diff --git a/resources/public/index.html b/resources/public/index.html index e1356ad..60c22d2 100644 --- a/resources/public/index.html +++ b/resources/public/index.html @@ -49,7 +49,11 @@ (let [response (gobject/get req "response")] (set! (.-innerText code) response) (.highlightElement js/hljs code)))) - (.send req))) + (.send req))) + + (set! (.-eval_input js/window) (fn [] + (let [value (.-value (js/document.getElementById "myInput"))] + (js/scittle.core.eval_string value)))) @@ -118,6 +122,12 @@ Click me! + +

Evaluate

+ + +

REPL

diff --git a/src/scittle/core.cljs b/src/scittle/core.cljs index 137434b..bce0ecc 100644 --- a/src/scittle/core.cljs +++ b/src/scittle/core.cljs @@ -33,8 +33,13 @@ (def !sci-ctx (atom (sci/init {:namespaces namespaces :classes {'js js/window :allow :all} - :disable-arity-checks true}))) - + :disable-arity-checks true + :async-load-fn (fn [{:keys [libname ctx opts]}] + (-> (js* (str "import('" libname "')")) + (.then (fn [mod] + (sci/add-class! ctx (:as opts) mod))) + (.then (fn [_] + {:handled true}))))}))) (def !last-ns (volatile! @sci/ns))