我有一个 html 画布,想在上面显示 Quil 草图。大多数 Quil 示例用于defsketch在静态 html 页面上定义的画布上进行绘制。我想在这个试剂组件中的画布上进行操作:
(defn my-component []
(reagent/create-class
{:component-did-mount (fn [this]
(let [canvas (reagent/dom-node this)
width (.-width canvas)
height (.-height canvas)]
(u/log (str "On canvas with width, height: " width " " height))))
:component-will-mount #(u/log "component-will-mount")
:display-name "my-component"
:reagent-render (fn [] [:canvas {:width 400}])}))
(defn graph-panel []
[v-box
:gap "1em"
:children [[my-component]]])
Run Code Online (Sandbox Code Playgroud)
我找到的执行此类操作的最佳文档是here,但我无法完全弄清楚如何进入下一个级别并将其应用到上面的画布。在上面的画布上画一条线的实际代码会很棒。
事实上,静态且始终运行defsketch就可以了 - 困难在于让它访问这种动态类型的画布。
如果无法完成,那么很高兴知道,我将直接使用Processing.js,假设这是下一个最佳想法。
当我期望 Alpha 表现得像 Beta 时,为什么它会提前停止?Alpha 和 Beta 之间的唯一区别是>!和put!,如下所述。
Α:
user=> (def q (chan))
#'user/q
user=> (def counter (atom 0))
#'user/counter
user=> (defn mg [event-queue]
#_=> (go-loop [event (<! event-queue)]
#_=> (swap! counter inc)
#_=> (when (< @counter 4)
#_=> (println "counter: " @counter)
#_=> (>! event-queue {:a @counter}) ;; Here's the only difference
#_=> (println "event: " event)
#_=> (recur (<! event-queue)))))
#'user/mg
user=> (mg q)
#object[clojure.core.async.impl.channels.ManyToManyChannel 0x3a1ffd56 "clojure.core.async.impl.channels.ManyToManyChannel@3a1ffd56"]
user=> (put! q "hi")
counter: true
1 …Run Code Online (Sandbox Code Playgroud) 我试图在我的re-frame/reagent/leiningen项目中使用cljsjs/vis,但将此库导入命名空间时出现错误。
cljsjs/vis in namespace required but not available
Run Code Online (Sandbox Code Playgroud)
已尝试使用其他库进行图表/数据可视化,但仍然有相同的结果。将 JS 库导入到 clojurescript 项目似乎有问题。
莱宁根project.cljs档案
(defproject test1 "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.10.1"]
[org.clojure/clojurescript "1.10.764"
:exclusions [com.google.javascript/closure-compiler-unshaded
org.clojure/google-closure-library
org.clojure/google-closure-library-third-party]]
[thheller/shadow-cljs "2.9.3"]
[reagent "0.10.0"]
[re-frame "0.12.0"]
[cljs-ajax "0.7.5"]
[cljsjs/vis "4.21.0-1"]]
:plugins [[lein-shadow "0.2.0"]
[lein-shell "0.5.0"]]
:min-lein-version "2.9.0"
:source-paths ["src/clj" "src/cljs"]
:clean-targets ^{:protect false} ["resources/public/js/compiled" "target"]
:shell {:commands {"open" {:windows ["cmd" "/c" "start"]
:macosx "open"
:linux "xdg-open"}}}
:shadow-cljs {:nrepl {:port 8777}
:builds {:app {:target :browser
:output-dir "resources/public/js/compiled"
:asset-path "/js/compiled"
:modules …Run Code Online (Sandbox Code Playgroud) 我想在cljs称为使用NPM包“systeminformation”
它的大部分功能都是异步的,有些是不异步
,但我无法使用异步功能,一切工作正常
有关的进口
[clojure.core.async :as async]
["systeminformation" :as systeminformation]
Run Code Online (Sandbox Code Playgroud)
我正在尝试运行的代码
(comment
(systeminformation/version) // WORKS FINE
(async/go
(async/<! (systeminformation/cpu))) // Gives me error
)
Run Code Online (Sandbox Code Playgroud)
错误:
INFO [mutesync.inspect.electron.background.main:30] - STACK
TypeError: c.cljs$core$async$impl$protocols$ReadPort$take_BANG_$arity$2 is not a function
at cljs$core$async$impl$ioc_helpers$take_BANG_ (D:\Tom\mutesync\.shadow-cljs\builds\electron-main\dev\out\cljs-runtime\cljs\core\async\impl\ioc_helpers.cljs:52:1)
at switch__47338__auto__ (<eval>:8:52)
at <eval>:32:29
at Function.fexpr__47378 [as cljs$core$IFn$_invoke$arity$1] (<eval>:54:4)
at Object.cljs$core$async$impl$ioc_helpers$run_state_machine [as run_state_machine] (D:\Tom\mutesync\.shadow-cljs\builds\electron-main\dev\out\cljs-runtime\cljs\core\async\impl\ioc
_helpers.cljs:43:3)
at cljs$core$async$impl$ioc_helpers$run_state_machine_wrapped (D:\Tom\mutesync\.shadow-cljs\builds\electron-main\dev\out\cljs-runtime\cljs\core\async\impl\ioc_helpers.cljs:45:1)
at <eval>:84:67
at Immediate.cljs$core$async$impl$dispatch$process_messages (D:\Tom\mutesync\.shadow-cljs\builds\electron-main\dev\out\cljs-runtime\cljs\core\async\impl\dispatch.cljs:26:7)
at processImmediate (internal/timers.js:456:21)
ERROR [mutesync.inspect.electron.background.main:68] - uncaught error
TypeError: c.cljs$core$async$impl$protocols$ReadPort$take_BANG_$arity$2 is not a function
Run Code Online (Sandbox Code Playgroud) (take 100 (iterate rand-int 300))
Run Code Online (Sandbox Code Playgroud)
当然,每次的评估都不同......但通常有很多零。结果始终以 300 开头。例如:
(300 93 59 58 25 14 9 4 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 …Run Code Online (Sandbox Code Playgroud) 我有一条记录,一个实例,并将其打印到 EDN 字符串:
(ns my)
(defrecord Ref [type id])
(def rich (->Ref :Person 42)
(pr-str rich)
Run Code Online (Sandbox Code Playgroud)
我想得到"#my.Ref [:Person 42].
但我明白了"#my.Ref{:type :Person, :id 23}"。
如何插入我的自定义实现来打印 的实例Ref?
这一直困扰着我.在repl我可以输入:
ClojureScript:cljs.user> (js* "window")
==> #<[object DOMWindow]>
ClojureScript:cljs.user> (js* "window.a=1")
==> 1
ClojureScript:cljs.user> (js* "window.a")
==> 1
Run Code Online (Sandbox Code Playgroud)
但如果我输入:
ClojureScript:cljs.user> (js* "c=1")
==> 1
ClojureScript:cljs.user> (js* "c")
=> ; expect 1 but returns nothing
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
在JQuery中我可以做类似的事情:
$("#p1").css("color","red").slideUp(2000).slideDown(2000);
Run Code Online (Sandbox Code Playgroud)
:它按顺序运行它们,但是当我在Clojurescript JayQ中尝试以下内容时:
(-> $("#p1")
(css "color" "red")
(slideUp 2000)
(slideDown 2000)
)
Run Code Online (Sandbox Code Playgroud)
:那么方法不会一个接一个地运行.有关如何做到这一点的任何想法?
我有一个小的Flask应用程序,我想使用一些ClojureScript来增强客户端的用户体验.
现在我无法通过烧瓶服务clojurescript,因为路径混乱了.
Flask声称像Javascript脚本这样的静态文件位于目录中static.我已经改变了我project.clj的编译目标放在那里:
:output-to "static/plot.js"
:output-dir "static"
Run Code Online (Sandbox Code Playgroud)
不幸的是,加载此文件时,它无法加载依赖文件goog.require:
"ClojureScript could not load :main, did you forget to specify :asset-path?"
Run Code Online (Sandbox Code Playgroud)
我相信缺少的是领导/static而不是static路径.
我可以为leiningen cljsbuild或clojurescript指定一个前缀吗?
我开发了一些应用程序,它从客户端获取数据并ns为其创建新数据.
应用程序执行一些操作后ns,调用函数等.
最后app返回一些输出,ns之后我删除了(remove-ns)
GC是否删除了该ns中的所有数据(对象)?
另一个问题是:为每个客户创建ns是明智的吗?我需要将客户端彼此隔离,这样就不会发生冲突.(并发用户)
lisp garbage-collection functional-programming clojure clojurescript
clojurescript ×10
clojure ×5
core.async ×2
reagent ×2
edn ×1
flask ×1
lisp ×1
python ×1
quil ×1
re-frame ×1