LightTable / Clojure

Light Table Clojure language plugin

Repository from Github https://github.comLightTable/ClojureRepository from Github https://github.comLightTable/Clojure

cljs problems

boxxxie opened this issue · comments

i'm getting a lot of errors when trying to run a chesnut template with core.async and cljs-http libs

workspace 1_018

project.clj

this is based on chesnut template

(defproject chesnut_test "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}

  :source-paths ["src/clj" "src/cljs"]

  :dependencies [[org.clojure/clojure "1.6.0"]
                 [org.clojure/clojurescript "0.0-2371" :scope "provided"]
                 [org.clojure/core.async "0.1.346.0-17112a-alpha"]
                 [cljs-http "0.1.21"]
                 [ring "1.3.1"]
                 [compojure "1.2.0"]
                 [enlive "1.1.5"]
                 [om "0.7.3"]
                 [figwheel "0.1.4-SNAPSHOT"]
                 [environ "1.0.0"]
                 [com.cemerick/piggieback "0.1.3"]
                 [weasel "0.4.0-SNAPSHOT"]
                 [leiningen "2.5.0"]]

  :plugins [[lein-cljsbuild "1.0.3"]
            [lein-environ "1.0.0"]]

  :min-lein-version "2.5.0"

  :uberjar-name "chesnut_test.jar"

  :cljsbuild {:builds {:app {:source-paths ["src/cljs"]
                             :compiler {:output-to     "resources/public/js/app.js"
                                        :output-dir    "resources/public/js/out"
                                        :source-map    "resources/public/js/out.js.map"
                                        :preamble      ["react/react.min.js"]
                                        :externs       ["react/externs/react.js"]
                                        :optimizations :none
                                        :pretty-print  true}}}}

  :profiles {:dev {:repl-options {:init-ns chesnut-test.server
                                  :nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}

                   :plugins [[lein-figwheel "0.1.4-SNAPSHOT"]]

                   :figwheel {:http-server-root "public"
                              :port 3449
                              :css-dirs ["resources/public/css"]}

                   :env {:is-dev true}

                   :cljsbuild {:builds {:app {:source-paths ["env/dev/cljs"]}}}}

             :uberjar {:hooks [leiningen.cljsbuild]
                       :env {:production true}
                       :omit-source true
                       :aot :all
                       :cljsbuild {:builds {:app
                                            {:source-paths ["env/prod/cljs"]
                                             :compiler
                                             {:optimizations :advanced
                                              :pretty-print false}}}}}})

core.cljs (just took the example code from cljs-http)

(ns chesnut-test.core
  (:require 
   [cljs-http.client :as http]
   [cljs.core.async :refer [buffer dropping-buffer sliding-buffer put! take! chan close! take partition-by <! >!] :as async]
   [cljs.core.async.impl.dispatch :as dispatch]
   [cljs.core.async.impl.buffers :as buff]
   [cljs.core.async.impl.timers :as timers :refer [timeout]]
   [cljs.core.async.impl.protocols :refer [full? add! remove!]])
  (:require-macros [cljs.core.async.macros :as m :refer [go alt!]]))

;;http examples

(go (let [response (<! (http/get "https://api.github.com/users" {:with-credentials? false}))]
      (prn (:status response))
      (prn (map :login (:body response)))))


;; POSTing automatically sets Content-Type header and serializes
(http/post "http://example.com" {:edn-params {:foo :bar}})


;; JSON is auto-converted via `cljs.core/clj->js`
(http/post "http://example.com" {:json-params {:foo :bar}})

;; Form parameters in a POST request (simple)
(http/post "http://example.com" {:form-params {:key1 "value1" :key2 "value2"}})

;; Form parameters in a POST request (array of values)
(http/post "http://example.com" {:form-params {:key1 [1 2 3] :key2 "value2"}})

;; HTTP Basic Authentication
(http/get
  "http://example.com"
  {:basic-auth {:username "hello" :password "world"}})

;; Pass prepared channel that will be returned,
;; e.g. to use a transducer.
(http/get "http://example.com" {:channel (chan 1 (map :body))})

;;END of http examples

index.html

<!DOCTYPE html>
<html>
  <head>
      <link href="public/css/style.css" rel="stylesheet" type="text/css">
  </head>
  <body>
    <div id="app"></div>
      <script src="public/js/out/goog/base.js" type="text/javascript"></script>
      <script src="public/js/app.js" type="text/javascript"></script>
  </body>
</html>

I'm able to eval the http/get lines using a fresh lein new chestnut chestnut_test. When you added your dependencies, did you restart your figwheel server? That's needed in order for those dependencies to get installed and to compile the cljs to js. LT doesn't handle compilation for you so you still need to lein cljsbuild ... or use figwheel if you prefer it. I mentioned it in the readme but perhaps we need to make that even more clear

ok. seems i really don't know what i'm doing with light table.
I was able to get things working.

I thought that i needed to have a browser open in light table for a clojurescript connection to work. i followed the instructions on chesnut (which is different from just running lein figwheel which is what i first tried).

I got things working now in light table.

I thought that i needed to have a browser open in light table for a clojurescript connection to work. i followed the instructions on chesnut (which is different from just running lein figwheel which is what i first tried).

You do need a browser connection if you want to do eval within Light Table.
Glad to hear you got it working.

for some reason i thought i had to open the index.html file in light table. then light table would do some magic...
i haven't done clojurescript before. so the instructions i was getting, from various sources, weren't fool proof.