Let's say you want to use cljs.js
to eval
code using functions declared in your project.
Expressions that only use core functions are simple to evaluate:
(ns foo.try-eval
(:require [cljs.js :as cljs]))
(def compiler-state (cljs/empty-state))
(ns layout.core | |
(:require | |
[sablono.core :include-macros true :refer-macros [html]] | |
[goog.dom :as gdom] | |
[om.next :as om :refer-macros [defui]])) | |
(def leaves | |
(atom {1 {:leaf/label "Root" | |
:leaf/id 1 |
; in clojure an if-then statement looks like: (if test do-this-if-true do-this-if-false) | |
; eg (if has-water (prn "content") (water-plant)) | |
(defn find-replace [zipper pred replacement] | |
(loop [loc zipper] ;begin a loop - when we call `recur` at the bottom,this is where we come back to. | |
(if (z/end? loc) ;if we are at the end, it means we've visited every node, so... | |
(root loc) ;we return the zipper | |
(if | |
(pred loc) ;`pred` is a function that we supply as a "test" for each location. eg. is this an 'x'? | |
(recur (z/next (z/replace loc (replacement loc)))) ;this is what we do if `pred` returned true |
Let's say you want to use cljs.js
to eval
code using functions declared in your project.
Expressions that only use core functions are simple to evaluate:
(ns foo.try-eval
(:require [cljs.js :as cljs]))
(def compiler-state (cljs/empty-state))
(ns cells.io | |
(:require | |
[cljs.core.async :refer [put! chan]] | |
[goog.net.XhrIo :as xhr])) | |
(defn GET [path] | |
(let [c (chan)] | |
(xhr/send path #(do | |
(put! c (-> % .-target .getResponseText)) "GET")) | |
c)) |
ClojureScript from master w/ zero dependencies
foo ├── build.clj
(cljs/eval (cljs/empty-state) | |
'(def x 1) | |
{:eval cljs/js-eval | |
:context :expr | |
:def-emits-var true | |
:ns cells.core | |
} | |
#(pprint %)) |
assuming you've already installed the Oculus runtime & it's working on your machine
; I want to use the files referenced in deps.cljs | |
; - CodeMirror must run before -overlay, -subpar, and -match-brackets. | |
(ns my-project.core | |
(:require | |
[CodeMirror] | |
[CodeMirror-overlay] | |
[CodeMirror-subpar] | |
[CodeMirror-match-brackets] | |
[reagent.core :as r :refer [cursor]] |
(ns app.layout | |
(:require | |
[reagent.core :as r] | |
[reagent.cursor :refer [cursor]])) | |
(defonce my-state (r/atom {1 "aaa" | |
2 "bbb"})) | |
(defn display-item [item-cursor id] | |
(fn [] |