Wednesday, August 8, 2018

clojurescript tips 1.0

Clojurescript:

You can access the browser state in the repl.  use
<namespace>/<atom-name>.
or change to the namespace using

(ns example.core)

Note: @ needs to be before a fully qualified variable!!!
(defn process-data
  (let [app-state @example.core/app-state]
    (example.horror/mangle! app-state)))

Do not use js/console.log to display clojure objects because javascript will display strange things.  Turn on (enable-console-print!) and then use (println xxxxxx).

You should also load the clojure formatters in your browser: https://github.com/binaryage/cljs-devtools/blob/master/docs/installation.md

This makes things look even better.


To stop figwheel from loading stuff on every reload, add a defonce variable and call the functions you only want run once.  The trick here is to set the variable to a non null value after running your functions.



1
2
3
4
5
(defonce setup-app
  (do
    (add-three-js-scene)
    (initialize-app)
    :done))  ;;setting setup-app to :done


No comments:

Post a Comment