Skip to content

Commit

Permalink
Remember namespaces across separate code blocks
Browse files Browse the repository at this point in the history
Before borkdude/cljs-showcase#1, our
separate code blocks could only use the  #'user namespace. Now, they
play nice with an ns declaration.
  • Loading branch information
kimo-k committed Jun 29, 2023
1 parent 25e36da commit 46cb48f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
7 changes: 4 additions & 3 deletions docs/dominoes-live.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ We'll look at all 70 lines.
Within our single namespace (of 70 lines), we'll need access to both `reagent` and `re-frame`.
So, at the top we need this:
<div class="cm-doc">
(require '[reagent.core :as reagent]
'[reagent.dom :as rdom]
'[re-frame.core :as rf])
(ns re-frame.simple
(:require [reagent.core :as reagent]
[reagent.dom :as rdom]
[re-frame.core :as rf]))
</div>

!!! Note "Live Code Fragment"
Expand Down
9 changes: 5 additions & 4 deletions docs/reagent.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ Clojurescript is ergonomic, stable, functional language
Look at the front page of https://www.learnreframe.com/


<div class="cm-doc">
(require '[reagent.dom :as rdom]
'[re-frame.core :as rf]
'[clojure.string :as str])
<div class="cljs-showcase">
(ns simple.core
(:require [reagent.dom :as rdom]
[re-frame.core :as rf]
[clojure.string :as str])))
</div>

<div class="cm-doc">
Expand Down
7 changes: 5 additions & 2 deletions docs/src/re_frame/docs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@
:ns-aliases {'clojure.pprint 'cljs.pprint}})]
(ctx-store/reset-ctx! ctx))

(defn eval-str [source-str]
(def last-ns (volatile! nil))

(defn eval-str [source-str & [opts]]
(try
(let [v (sci/eval-string* (ctx-store/get-ctx) source-str)]
(let [{:keys [v ns]} (sci/eval-string+ (ctx-store/get-ctx) source-str {:ns @last-ns})]
(vreset! last-ns ns)
(if (instance? js/Promise v)
(-> v
(.then
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
:plugins [[com.github.liquidz/antq "RELEASE"]
[lein-shell "0.5.0"]]
:antq {}}
:docs {:dependencies [[org.babashka/sci "0.7.39"]
:docs {:dependencies [[org.babashka/sci "0.8.40"]
[funcool/promesa "10.0.575"]]}}

:clean-targets [:target-path
Expand Down

0 comments on commit 46cb48f

Please sign in to comment.