Skip to content

Instantly share code, notes, and snippets.

@hiteshjasani
Last active February 26, 2018 17:15
Show Gist options
  • Save hiteshjasani/25c0182e8ad358fc2b1b8cd1dafbf4ef to your computer and use it in GitHub Desktop.
Save hiteshjasani/25c0182e8ad358fc2b1b8cd1dafbf4ef to your computer and use it in GitHub Desktop.
Clojurescript synthetic index examples

Examples of using clj with deps to create a very minimal clojurescript web page.

Run

  1. Download the files from this gist.
  2. Run them with make run or make run-reagent
  3. Point browser to http://localhost:9000
  4. Type commands in the REPL
(require '[index-reagent :as ir])
(ir/mountit)
;; See content in web page
(ir/change-message "I'm in your machine twiddling your bits.")
;; see updated web page
(ns index)
(set! (.-innerHTML (.getElementById js/document "app"))
"<div><h2>Hello from cljs!</h2><p>This is a hardcoded message.</p></div>")
(ns index-reagent
(:require [reagent.core :as r]))
(defonce app-state (r/atom {:msg "hello"}))
(defn change-message
[new-message]
(swap! app-state assoc :msg new-message))
(defn render-app []
[:div
[:h1 "My Reagent app"]
[:p "this was rendered by reagent"]
[:h2 "Stand by for a message"]
[:p (str "message is ... " (:msg @app-state))]])
(defn mountit []
(r/render [render-app]
(.getElementById js/document "app")))
run:
clj -Sdeps '{:paths ["."] :deps {org.clojure/clojurescript {:git/url "https://github.com/clojure/clojurescript" :sha "ec0e4c49fa5bf97d6c8b5a8e5d3bd957855bfe56"}}}' -m cljs.main -re browser -c index -r
run-reagent:
clj -Sdeps '{:paths ["."] :deps {org.clojure/clojurescript {:git/url "https://github.com/clojure/clojurescript" :sha "ec0e4c49fa5bf97d6c8b5a8e5d3bd957855bfe56"} reagent {:mvn/version "0.8.0-alpha2"}}}' -m cljs.main -re browser -c index-reagent -r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment