A SPA written in ClojureScript.
Uses re-frame to drive an Always-Agent configuration page.
You will need admin
and web-services
running locally
on the 8838-always-agent
branch.
There are at least 3 ways to integrate existing React components into ClojureScript:
- CLJSJS
- 'Double Bundle'
- Shadow-CLJS
The first method is done completely with CLJS,
while the other two methods use package.json
and other NPM/JS tools.
CLJSJS wraps common JS libraries into CLJS components. This approach is simple, but if the library or version we want is not available, unless we want to try creating a CLJSJS module, this method will not work.
Advantage: Simple and seamless to use, no JS needed.
The 'Double Bundle' approach uses Webpack to build the NPM dependencies into one JS file, and uses standard CLJS tools to build the app code as a separate file. Both are referenced in the HTML, with the NPM bundle first. There are some drawbacks.
- Must create synthetic namespaces for some CLJSJS dependencies.
- Must use
get
on global object to access the object and use it. - Advanced compilation might not work yet.
Advantage: Uses standard tools for JS and CLJS: NPM and cljs-build, respectively.
Shadow-CLJS is a NPM tool for compiling CLJS using existing ClojureScript and JS tools. It does a better job of handling external libraries, integrating with and even replacing other tools. But there are tradeoffs.
- A new tool is introduced into the build chain.
- A
shadow-cljs.edn
configuration file is needed. - An unusual quoted
require
statement is needed.
Advantages: One tool handles JS and CLJS, including dependencies.
Method | Additional Required Tools | Source Annotation | Development Endpoint |
---|---|---|---|
CLJSJS | None | _CLJSJS_ |
localhost:3449 |
Double Bundle | NPM, Webpack | _DOUBLE_ |
localhost:3449 |
Shadow CLJS | NPM, Shadow-CLJS | _SHADOW_ |
localhost:8080/shadow.html |
No special instructions. See below for Figwheel startup.
npm i
npm run-script build
lein figwheel
Figwheel will automatically push cljs changes to the browser.
Wait a bit, then browse to http://localhost:3449.
npm i
shadow-cljs watch app
The command above gives a HUD similar to Figwheel.
Browse to http://localhost:8080/shadow.html
As you edit source code, changes are automatically pushed to the browser. You will see the Shadow-CLJS spinner when this happens. Errors will also be displayed in the browser and the console, just like Figwheel.
CIDER will connect to Figwheel apps out of the box with cider-jack-in-clojurescript
.
Shadow-CLJS will connect as well, with just a bit more work:
Put this in your Emacs config file:
(setq cider-cljs-lein-repl
"(do (require 'figwheel-sidecar.repl-api)
(figwheel-sidecar.repl-api/start-figwheel!)
(figwheel-sidecar.repl-api/cljs-repl))")
NB: This step may no longer be necessary with current CIDER
Now start a watch
build (see above), navigate to a CLJS file, and connect:
To connect to older CIDER:
- Run
cider-connect
in emacs. - Respond when prompted to enter the hostname and port.
- In the CIDER REPL when it is ready, run this command:
(shadow.cljs.devtools.api/repl :app)
- try devcards with the shadow build
- research re-frame subscription derefs and determine where best to place them when passing to components