clojurescript

ClojureScript and closure: how to protect attributes from being renamed by closure

こ雲淡風輕ζ 提交于 2019-12-05 13:40:22
I am trying to to some HTML5 canvas drawing and I ran across a problem with the advanced compilation mode. I would like to exemplify this with the mozDash property of Mozilla browsers (although this question is quite generic on the attribute optimization feature) https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D#Gecko-specific_attributes The javascript canvas.mozDash = ... code can be expressed as [1] (set! (.-mozDash canvas) ...) or [2] (aset canvas "mozDash" ...) in Clojurescript. I had used [1] before and it worked in most cases, however with the mozDash attribute

how can macros be evaluated using the clojurescript repl

核能气质少年 提交于 2019-12-05 12:48:54
Once the browser is connected to the clojurescript repl, I previously had no way of calling macros from the repl. This is an issue that has put me off clojurescript in the past, preferring using javascript directly. Basically, I felt that the cljs-repl was kinda lame and I was going back to the compile/debug cycle that writing code in clojure was supposed to emancipate us from. Are there any good workarounds/workflows for pushing and testing code in clojurescript? Especially if macros can be evaluated? An example of my problem is: make a new cljs project lein new cljs-template blah start up

How can I deploy a Leiningen template to Clojars?

余生长醉 提交于 2019-12-05 12:32:14
I have created a Leiningen project on my local machine which I then turn into a template by doing: lein create-template webdb : Then I install the template: cd webdb lein install : which allows me to create projects based on the template locally: lein new webdb anewproject : Everything works fine up to here. However if I try to deploy the template to clojars using: cd webdb lein deploy clojars : then whenever I try to use the clojars profile to create a template I get an error: lein new org.clojars.zubairq2/webdb anothernewproject : gives the error: Could not find metadata org.clojars.zubairq2

What should an om component return to render nothing?

人盡茶涼 提交于 2019-12-05 12:28:59
Is it possible to write a component that renders nothing, for example, if its cursor data is empty ? I can not do (defn count-or-nothing [list-cursor owner] (reify om/IRender (render [_] (if (not (empty? list-cursor)) (dom/div nil "You have some elements !"))))) The if clause returns nil, which causes an error message Uncaught Error: Invariant Violation: ReactCompositeComponent.render(): A valid ReactComponent must be returned. You may have returned null, undefined, an array, or some other invalid object. I got by, by rendering an empty span, but that sounds clumsy. Do I necessarily have to

How to memoize a function that uses core.async and non-blocking channel read?

混江龙づ霸主 提交于 2019-12-05 12:19:12
I'd like to use memoize for a function that uses core.async and <! e.g (defn foo [x] (go (<! (timeout 2000)) (* 2 x))) (In the real-life, it could be useful in order to cache the results of server calls) I was able to achieve that by writing a core.async version of memoize (almost the same code as memoize): (defn memoize-async [f] (let [mem (atom {})] (fn [& args] (go (if-let [e (find @mem args)] (val e) (let [ret (<! (apply f args))]; this line differs from memoize [ret (apply f args)] (swap! mem assoc args ret) ret)))))) Example of usage: (def foo-memo (memoize-async foo)) (go (println (<!

Is there an online tool to auto-indent and format Clojure code like there are many for JSON?

佐手、 提交于 2019-12-05 10:52:31
问题 There are a lot of tools online that take a JSON text and show you formatted and well indented format of the same. Some go even further and make a nice tree-like structure: http://jsonviewer.stack.hu/ Do we have something similar for Clojure code ? Or something that can at least auto-indent it. If the text that I have is this : (defn prime? [n known](loop [cnt (dec (count known)) acc []](if (< cnt 0) (not (any? acc)) (recur (dec cnt) (concat acc [(zero? (mod n (nth known cnt)))]))))) It

How can I get the Clojurescript namespace I am in from within a clojurescript program?

早过忘川 提交于 2019-12-05 05:15:19
How can I get the Clojurescript namespace I am in from within a clojurescript program? I want to do this do provide certain debug information (it only needs to work in dev mode) Namespaces are not first class in ClojureScript as they are in Clojure. There's absolutely no way to get the namespace at runtime. It is possible to get this information at macroexpansion time if you're not afraid of accessing some the ClojureScript compiler internals. There should probably be an API for this - but we're not there yet. You can get the name of the current namespace with this trick, which takes advantage

How can I use Clojurescript to interact with the html DOM?

£可爱£侵袭症+ 提交于 2019-12-05 04:34:15
I am new to Clojurescript. I want to know how to create html elements, and how to change their properties using clojurescript. I cannot seem to find a lot of relevant information online. ClojureScript provides good interoperability with JavaScript and the browser. You can call JavaScript globals and functions directly to query and manipulate DOM like so: (-> js/document (.getElementById "app") (.-innerHTML)) ; returns contents of element with id 'app' (-> js/document (.getElementById "app") (.-innerHTML) (set! "Hello Clojure!")) ; Sets new content for element Checkout ClojureScript cheatsheet

ClojureScript clojure.set?

感情迁移 提交于 2019-12-05 02:19:07
How can I use clojure.set in ClojureScript? I always get a error. (def middle-land (set (for [x water-hor y (vec (clojure.set/difference (set (range 0 board-side)) (set water-ver)))] [x y]))) ReferenceError: clojure is not defined Seems you need to explicitly require the namespace to be able to use it: ClojureScript:cljs.user> (ns core (:require clojure.set)) ClojureScript:core> (clojure.set/difference #{1 2} #{1 4}) ;=> #{2} 来源: https://stackoverflow.com/questions/21367433/clojurescript-clojure-set

Drag and drop events in embedded SVG?

会有一股神秘感。 提交于 2019-12-05 01:53:11
Is there any possibility of receiving drag and drop events from SVG elements within a web page? I tried the Google Closure library, to no avail. Specifically, suppose my page contains <ul id = "list"> <li class="item" id="item1">foo</li> <li class="item">bar</li> <li class="item">baz</li> </ul> And my script contains (Clojurescript/C2) (let [items (select-all ".item") lst (select "#list") target (fx/DragDrop. lst nil)] (dorun (map (fn [item] (let [source (fx/DragDrop. item nil)] (. source (addTarget target)) (. source (init)))) items)) (. target (init))) Then I do get a drag image (ghost),