REPLからの開発
% clj -A:fig:build
2021-07-12 20:59:23.174:INFO::main: Logging initialized @5649ms to org.eclipse.jetty.util.log.StdErrLog
[Figwheel] Validating figwheel-main.edn
[Figwheel] figwheel-main.edn is valid \(ツ)/
[Figwheel] Compiling build dev to "target/public/cljs-out/dev-main.js"
[Figwheel] Successfully compiled build dev to "target/public/cljs-out/dev-main.js" in 2.531 seconds.
[Figwheel] Outputting main file: target/public/cljs-out/dev-main-auto-testing.js
[Figwheel] Watching paths: ("test" "src") to compile build - dev
[Figwheel] Starting Server at http://localhost:9500
[Figwheel] Starting REPL
Prompt will show when REPL connects to evaluation environment (i.e. a REPL hosting webpage)
Figwheel Main Controls:
(figwheel.main/stop-builds id ...) ;; stops Figwheel autobuilder for ids
(figwheel.main/start-builds id ...) ;; starts autobuilder focused on ids
(figwheel.main/reset) ;; stops, cleans, reloads config, and starts autobuilder
(figwheel.main/build-once id ...) ;; builds source one time
(figwheel.main/clean id ...) ;; deletes compiled cljs target files
(figwheel.main/status) ;; displays current state of system
Figwheel REPL Controls:
(figwheel.repl/conns) ;; displays the current connections
(figwheel.repl/focus session-name) ;; choose which session name to focus on
In the cljs.user ns, controls can be called without ns ie. (conns) instead of (figwheel.repl/conns)
Docs: (doc function-name-here)
Exit: :cljs/quit
Results: Stored in vars *1, *2, *3, *e holds last exception object
[Rebel readline] Type :repl/help for online help info
Opening URL http://localhost:9500
ClojureScript 1.10.773
cljs.user=> (+ 3 4)
rlwrap: warning: rlwrap appears to do nothing for clojure, which asks for
single keypresses all the time. Don't you need --always-readline
and possibly --no-children? (cf. the rlwrap manpage)
warnings can be silenced by the --no-warnings (-n) option
7
cljs.user=> "New\nLine"
"New\nLine"
cljs.user=> (println "New\nLine")
New
Line
nil
cljs.user=> (in-ns 'learn-cljs.weather) ;;アプリのメインネームスペースに入る
learn-cljs.weather=> (def input (.createElement js/document "input")) ;;input要素を作成し、DOMに追加します。
#'learn-cljs.weather/input ;;defの評価値が定義されたvarになる
learn-cljs.weather=> (.appendChild (.-body js/document) input)
#object[HTMLInputElement [object HTMLInputElement]]
learn-cljs.weather=> (set! (.-placeholder input) "Enter something") ;;要素のplaceholderプロパティを変更する
"Enter something"
learn-cljs.weather=> (defn handle-input [e] ;;イベントハンドラを作成し、inputにアタッチする。
#_=> (swap! app-state assoc :text (-> e .-target .-value)))
#'learn-cljs.weather/handle-input
learn-cljs.weather=> (set! (.-onkeyup input) handle-input)
#object[learn_cljs$weather$handle_input]
learn-cljs.weather=> (defn event-value [e]
#_=> (-> e .-target .-value))
#'learn-cljs.weather/event-value
learn-cljs.weather=> (defn update-text [v]
#_=> (swap! app-state assoc :text v))
#'learn-cljs.weather/update-text
learn-cljs.weather=> (defn handle-input [e]
#_=> (update-text (event-value e)))
#'learn-cljs.weather/handle-input
learn-cljs.weather=>