如何在ClojureScript中使用Spectre?

时间:2016-08-24 12:33:24

标签: clojure namespaces clojurescript specter

我很难在cljs中使用幽灵(0.12.0)。我可能没有正确设置ns。

运行一个简单示例我收到以下错误消息:

=> (select [:a :b] {:a {:b 42}})
#object[TypeError TypeError: Cannot read property 'specter' of undefined]

我的ns看起来像这样:

(ns dummy.core
  (:require [com.rpl.specter :as s])
  (:require-macros [com.rpl.specter.macros :refer [select]]))

修改

它实际上可以在浏览器中使用。

但它不是在figwheel的REPL中,我自然而然地在那里尝试过它。

我的project.clj(为了简洁而略微缩短)

(defproject dummy "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.8.0" :scope "provided"]
                 [org.clojure/clojurescript "1.7.228" :scope "provided"]
                 [reagent "0.5.1"]
                 [com.rpl/specter "0.12.0"]]

  :plugins [[lein-cljsbuild "1.1.1"]]
  :min-lein-version "2.5.0"
  :clean-targets ^{:protect false}
    [:target-path
      [:cljsbuild :builds :app :compiler :output-dir]
      [:cljsbuild :builds :app :compiler :output-to]]

  :resource-paths ["public"]

  :cljsbuild {:builds {:app {:source-paths ["src"]
                             :figwheel {:on-jsload dummy.core/fig-reload}
                             :compiler {:main dummy.core
                                        :output-to "public/js/app.js"
                                        :output-dir "public/js/out"
                                        :source-map-timestamp true
                                        :asset-path   "/js/out"
                                        :optimizations :none
                                        :pretty-print  true}}

                       :min {:source-paths ["src"]
                             :compiler {:main dummy.core
                                        :output-to "public/js/app.js"
                                        :optimizations :whitespace}}}}

  :figwheel { :http-server-root "public"
              :server-port 3449
              :nrepl-port 7002
              :nrepl-middleware ["cemerick.piggieback/wrap-cljs-repl"]
              :css-dirs ["public/css"]}

  :profiles { :dev { :dependencies [[prone "1.0.2"]
                                    [lein-doo "0.1.6"]
                                    [pjstadig/humane-test-output "0.7.1"]
                                    [lein-figwheel "0.5.0-6"]
                                    [org.clojure/tools.nrepl "0.2.12"]
                                    [com.cemerick/piggieback "0.2.1"]]

                     :plugins [[lein-figwheel "0.5.0-6"]
                               [lein-doo "0.1.6"]]

                     :doo {:build "test"}

                     :injections [(require 'pjstadig.humane-test-output)
                                  (pjstadig.humane-test-output/activate!)]}})

2 个答案:

答案 0 :(得分:2)

FWIW我有几个路障让幽灵进入clojurescript,但现在似乎工作正常。道路颠簸是必须拉入两个名称空间并确定哪个Specter位于哪个名称空间中。 Nathan Marz说他想要unify them eventually,但在那之前,我的命名空间看起来像这样:

(ns test.core
  (:require [com.rpl.specter :as sp])
  (:require-macros [com.rpl.specter.macros :refer [select setval] :as spm]))

所以,与你的不同之处!但至少看起来你可以排除你的命名空间defn。顺便说一下,这对我来说也很合适。顺便说一下。我使用Devcards作为lein new devcards test的起点,并使用了project.clj

答案 1 :(得分:0)

现在幽灵可以在Clojurescript中使用如下

(ns test.core
  [com.rpl.specter :as s])

(def breakpoints ["320px" "600px" "1280px"])

(def styles {:padding-top ["20px" "30px" "40px" "50px"]
             :margin ["60px"]})


(s/transform [s/MAP-VALS] #(%1 0) styles)

(s/setval [s/MAP-VALS s/FIRST] s/NONE styles)