-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<html> | ||
<head> | ||
<script src="../js/scittle.js" type="application/javascript"></script> | ||
<script crossorigin src="https://unpkg.com/react@17/umd/react.production.min.js"></script> | ||
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script> | ||
<script src="../js/scittle.reagent.js" type="application/javascript"></script> | ||
<script type="application/x-scittle"> | ||
(require '[reagent.core :as r] | ||
'[reagent.dom :as rdom]) | ||
|
||
(def state (r/atom {:clicks 0})) | ||
|
||
(defn my-component [] | ||
[:div | ||
[:p "Clicks: " (:clicks @state)] | ||
[:p [:button {:on-click #(do (print :foo) (println :dude) (prn (with-out-str (prn :foo))) (swap! state update :clicks inc))} | ||
"Click me!"]]]) | ||
|
||
(rdom/render [my-component] (.getElementById js/document "app")) | ||
</script> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(ns scittle.impl.common | ||
(:require [sci.core :as sci])) | ||
|
||
(def cljns (sci/create-ns 'clojure.core nil)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(ns scittle.impl.io | ||
(:refer-clojure :exclude [prn print println with-out-str]) | ||
(:require | ||
[cljs.core :as c] | ||
[goog.string] | ||
[sci.core :as sci] | ||
[scittle.impl.common :refer [cljns]])) | ||
|
||
(def print-fn (sci/copy-var *print-fn* cljns)) | ||
(def print-newline (sci/copy-var *print-newline* cljns)) | ||
|
||
(defn println [& objs] | ||
(binding [*print-fn* @print-fn | ||
*print-newline* @print-newline] | ||
(apply c/println objs))) | ||
|
||
(defn prn [& objs] | ||
(binding [*print-fn* @print-fn | ||
*print-newline* @print-newline] | ||
(apply c/prn objs))) | ||
|
||
(defn print [& objs] | ||
(binding [*print-fn* @print-fn] | ||
(apply c/print objs))) | ||
|
||
(defn ^:macro with-out-str | ||
"Evaluates exprs in a context in which *print-fn* is bound to .append | ||
on a fresh StringBuffer. Returns the string created by any nested | ||
printing calls." | ||
[_ _ & body] | ||
`(let [sb# (goog.string/StringBuffer.)] | ||
(binding [cljs.core/*print-newline* true | ||
cljs.core/*print-fn* (fn [x#] (.append sb# x#))] | ||
~@body) | ||
(cljs.core/str sb#))) |