clojurescript

How to add a child to a tree using clojure.zip?

谁都会走 提交于 2019-12-11 10:54:11
问题 Consider the following code (def v (z/vector-zip [1 [2 [3 4]]])) where z refers to clojure.zip. Now, how do I create from v the vector [1 [2 [3 [4 5]]]] using functions from the API for clojure.zip ? So starting with (-> v ... 回答1: Just use function edit (defn edit "Replaces the node at this loc with the value of (f node args)" [loc f & args] (replace loc (apply f (node loc) args))) Example (-> v (z/down) (z/right) (z/down) (z/right) (z/down) (z/right) (z/edit #(do [% 5])) (z/root)) And the

Clojurescript - Uncaught Error: <! used not in (go …) block

*爱你&永不变心* 提交于 2019-12-11 09:15:25
问题 I am in Clojurescript, and trying to use core.async to get a result from a native Javascript function (I am in the browser), and conditionally integrate it into a map. I have a function to wrap a native browser call (inspired by Timothy Baldridge's talk on core.async, approx. 34 min for those interested) : (defn geolocation [] (let [c (chan) cb (fn [e] (put! c (js->clj e)))] (if (exists? js/navigator.geolocation) (.getCurrentPosition js/navigator.geolocation. cb cb) (put! c {:error

How to handle cljs-ajax responses?

这一生的挚爱 提交于 2019-12-11 02:36:48
问题 I am making a request from a clojurescript frontend with cljs-ajax to an API that responds with JSON but it seems like I need to do something to it before I can use it in cljs. (defn all-pieces [] (GET "/art/pieces" {:handler ajax-success-handler})) When I initialize my app-state I assign the key :all-pieces (all-pieces) When I go to iterate over :all-pieces in a component I get the error Uncaught Error: [object Object] is not ISeqable . (defn pieces-component [] [:ul (for [piece (:all-pieces

How to use common dependencies in different clojurescript projects?

喜夏-厌秋 提交于 2019-12-11 02:35:13
问题 I wrote a clojurescript project. It is a reagent component. Now i want to use this component in other clojurescript project. That is what i do: I compiled my cljs project and then i put a result compiled file to js folder in other project. Further i require that file from index.html. At the end i invoke my component from cljs file (.slider-view (.-views js/swipe) (clj->js [[:p "1"] [:p "2"] [:p "3"]])) and it works. But i have a question. My project and project where i connect my component

What is the ClojureScript analogue of delete from JavaScript?

别来无恙 提交于 2019-12-11 01:15:15
问题 I'm seeing lots of code using the pattern: delete b[d]; Now I'm translating this to: (aset b d nil) Is that appropriate - or am I losing some crucial data? My question is: **What is the ClojureScript analogue of delete from JavaScript? ** 回答1: According to http://cljs.info/cheatsheet/ it's js-delete (js-delete b d) 来源: https://stackoverflow.com/questions/36840372/what-is-the-clojurescript-analogue-of-delete-from-javascript

clojurescript: touch events and Domina

二次信任 提交于 2019-12-11 00:45:14
问题 I'm having trouble getting the 'touch' or 'changedTouches' list out of the touchstart event in Domina. Here's my :require stuff: (ns myproj (:require-macros [hiccups.core :as h]) (:require [domina :as dom] [hiccups.runtime :as hiccupsrt] [domina.events :as ev] [cljs.reader :refer [read-string]] [wsosc :as wo] [clojure.browser.repl :as repl] )) And here's my touchstart event handler: (defn touchstart [evt] ; store event in an atom for repl access (swap! de (fn [x] evt)) ; print something to

How do I search for special characters in Clojure?

怎甘沉沦 提交于 2019-12-10 17:37:24
问题 Clojure uses a number of special characters such as ^String #(xyz ...) %& #_(some form here) >! and many more. How can I search for documentation for these special characters, given that Google et al mostly ignore special characters in web pages and search strings? 回答1: This question and others have raised an important topic: it can often be difficult and frustrating to find documentation on special characters used in Clojure source code. The first place to look is the Clojure docs themselves

How can I get the positions of regex matches in ClojureScript?

白昼怎懂夜的黑 提交于 2019-12-10 16:36:50
问题 In Clojure I could use something like this solution: Compact Clojure code for regular expression matches and their position in string, i.e., creating a re-matcher and extracted the information from that, but re-matcher doesn't appear to be implemented in ClojureScript. What would be a good way to accomplish the same thing in ClojureScript? Edit: I ended up writing a supplementary function in order to preserve the modifiers of the regex as it is absorbed into re-pos : (defn regex-modifiers

Clojure: for for n Dimensions

强颜欢笑 提交于 2019-12-10 16:03:42
问题 In Clojure the function for can be used for iterating nested sequences. Imagine a 3D space with a x-, y- and z-axis: (for [x (range 10) y (range 5) z (range 2)] [x y z]) The code above would produce a sequence of vectors which represents all possible positions inside a cuboid. (limited to the positions which indices are natural numbers of course) Does anybody know a good way to make this more generic? Meaning, to make it work if you have not a number of 3 but of n dimensions. 回答1: Most

Clojurescript: converting cljs map to a javascript hash

北战南征 提交于 2019-12-10 12:39:33
问题 The following code snippet does not work headerElement (goog.dom/createDom "div" (.strobj {"style" "background-color:#EEE"}) (:title note)) Reason: { ... } creates a Clojurescript map. I need a javascript object/hash. Question: How do I make this trivial conversion? 回答1: cljs.core/js-obj should help for this. Please notice that it takes normal array/list in (not a map). headerElement (goog.dom/createDom "div" (js-obj "style" "background-color:#EEE") (:title note)) 回答2: You can also use #js