emacs,clojure,clojurescript,cider
^M is windows line ending. Answer how ho hide it in Emacs can be found here. Printing of nil in general is normal behaviour and it's not specific to Clojurescript or Emacs. All forms return a value (which may be nil) and also may produce side-effects: cljs.user> (println 1) 1...
clojure,functional-programming,clojurescript
(map #(% arg) function-list) Should do the job?...
This code works as expected. When I click on "Click Me!", while looking at the Elements in Developer Tools (Chrome), I see the class toggling between "awesomeclass" and disappearing: (defonce app-state (atom {:some-key true})) (defn main [] (om/root (fn [app owner] (reify om/IRender (render [_] (html [:div {:class (when (:some-key...
Using js/a.b.c.d is a bad practice and is likely to break in future versions of the compiler (because it is not a clojure compatible version of interop from what I know) The good way would be: (def LatLng (.. js/google -maps -LatLng)) (LatLng. 100 100) ...
Okay, got it. Here's an example: (bind ($ "selection") "click" (this-as somename (js/alert somename))) ...
data-structures,clojure,sequence,clojurescript,seq
If you need the order of the data, you have the following possibilities: Store the data once in order and once as a map. So, when adding a new entry, do something like: (defn add-entry [uid data] (swap! app-state update-in ["my-seq"] #(-> % (update-in [:sorted] conj data) (update-in [:by-uid] assoc...
I'm not sure if it's the simplest way to write it, but I think this is more clear about your intentions: (->> maps (filter #(= (:id %) id)) first) ...
javascript,clojure,clojurescript,om,reagent
(.toDateString (js/Date. 1420971497471)) ...
It think that will-mount is not a good place to update cursor. Calling om/build with the :fn option will do what you're trying to achieve. Component is rendered only once, with the updated cursor. (om/build mycomponent data {:fn #(assoc % :text "Success !")}) https://github.com/swannodette/om/wiki/Documentation#build...
javascript,firebase,clojurescript
Firebase expects a JavaScript object to its API calls. You are passing it a Clojure data structure (in this case a map). You have to convert your Clojure data structure to a JavaScript object before passing it to the Firebase function. So instead of: (.push fb postData) you need to...
I don't know any function that does that. It is also necessary to define whether you want the map to contain every key or just some keys. I chose the every case, if you wanted the some version, just replace every? with some?. My direct, not optimized, version is: (defn...
Your question is sensible and it's about handling scope of data. It is possible but the problem with this approach in most cases you will need local scope data from the outside code block (in your case, it's an Om component). I would explain in code. Let's say you want...
console,clojurescript,idiomatic
(enable-console-print!) just sets *print-fn* to console.log. After calling (enable-console-print!) both (println ...) and (.log js/console ...) are functionally equivalent. However use of println has 3 benefits: There is no explicit interop with JavaScript which makes code cleaner You have possibility to change logging functionality in one place - just set...
The following versions work for me: (defproject hello-world "0.1.0-SNAPSHOT" :description "FIXME: write this!" :url "http://example.com/FIXME" :dependencies [[org.clojure/clojure "1.5.1"] [org.clojure/clojurescript "0.0-2173"]] :plugins [[lein-cljsbuild "1.0.2"]] :cljsbuild { :builds []}) Updating to lein-cljsbuild 1.0.3 and clojurescript 0.0-2197 seems to break the rhino repl....
javascript,settimeout,setinterval,clojurescript,seq
This, for example, works: (def container (sel1 :#container)) (def integers (iterate inc 0)) (defn set-int! [[x & rs :as nums]] (when nums (js/setTimeout #(do (dommy/set-text! container i) (set-int! rs)) 1000))) (set-int! integers) Anyway, what are you trying to accomplish? It is a pretty weird way of making a counter, and...
In comparison to clojure where it would be possible to use :refer :all it is not possible in clojurescript. You can find the proper answer in here : Is it possible to use :refer :all in a ClojureScript :require? However, you can do is this: (:require-macros [webapp.framework.client.coreclient :as client]) And...
Yes it is possible. Browser repl, noderepl, rhino repl... Checkout the docs and read about piggieback. That's how it handles the envs https://github.com/tpope/vim-fireplace/blob/master/doc/fireplace.txt https://github.com/cemerick/piggieback Piggieback is included on Austin too so it should work if you :Connect to Austin and then :Piggieback with the environment you want Edit: example Read...
As sbensu says with-meta only seems to work in reagent on a function. This means it can be used with identity to produce a reusable wrapper as hoped (def initial-focus-wrapper (with-meta identity {:component-did-mount #(.focus (reagent/dom-node %))})) (defn chat-input [] (fn [] [initial-focus-wrapper [:input {:type "text"}]])) ...
clojure,merge,state,clojurescript
It is simpler than all that (having a vector of maps is something pretty common, and it may fit your problem properly). Instead of doing a filter and then a map, just do a map: (defn update? [entity] ...) (defn update-entity [entity] ...) (defn update-world [world] (let [update #(if (matches?...
You need to use the #js {} reader literal to specify a JS object rather than a plain-old map: (dom/div #js {:id "some-id"} "Pumpkin") This is elaborated a bit in the Om Tutorial....
function,clojure,clojurescript
Have a look at the function some, that takes a predicate and a collection as arguments, and returns true iff the predicate returns true for some item in the collection. (some #(>= % 3) [1 2 3 4]) ; => true (some #(>= % 3) [0 1 0 1]) ;...
clojure,reactjs,clojurescript,reagent
You should use reagent.core/atom instead of regular Clojure atom. Add this to your namespace :require: [reagent.core :as reagent :refer [atom]] ...
clojure,clojurescript,core.async
Something like this might work for you: (defn my-fn [a f pred] (let [pending? (atom false) f (fn [] (reset! pending? false) (f @a))] (add-watch a (gensym) (fn [_k _a _old-val new-val] (when (and (not @pending?) (pred new-val)) (reset! pending? true) (if (exists? js/requestAnimationFrame) (js/requestAnimationFrame f) (js/setTimeout f 16))))))) ...
Yes, this is possible (cf. how to use a complex return object from clojurescript in javascript… for instance). As you already figured out, ClojureScript will be compiled to normal JavaScript files (where "normal" varies according to your cljsbuild settings on how aggressive the output will be optimized). This is more...
The answer was to use goog.object.forEach: (defn clone-object [key obj] (goog.object/forEach obj (fn [val key obj] (log/debug key)))) ...
Inside the body of a macro, (:ns &env) will be truthy when expanding in ClojureScript but not in Clojure. This is currently the "best practice" for writing platform-specific macros: (defmacro platform [] (if (:ns &env) :CLJS :CLJ)) ...
Your example is not working because you have to pass a function to :on-click like this : [:li [:a {:on-click #(reset! selected-department "test!")} "Dairy"]] So the only thing that you need to change is to add # before the (reset! ... It is the equivalent for [:li [:a {:on-click (fn...
That's one of the forms for clojurescript interop. The most basic one is (.method object) ; Equivalent to object.method() (.-property object) ; Equivalent to object[property] In order to access several nested properties, there is a shortcut with the .. operator, so that you can do: (.. object -property -property method)...
The ring middleware wrap-reload will do this for you. There is also a very nice leiningen template called Chestnut which will set up a project for you with Figwheel and an auto reloading Ring backend. This question shows an example of wrap-reload usage Compojure development without web server restarts...
javascript,clojurescript,lighttable
Found the problem.. I didn't include the cljs script file into the html file. After including the cljs file inside the html, and run lein cljsbuild [once|auto] everything's ok.....
reactjs,clojurescript,inline-styles,om
I found an example in the Om source code, which led me to try this, which works: (dom/img #js {:className "img-circle" :src "data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" :style #js {:width "140px" :height "140px"} :alt "Generic Placeholder Image"}) ...
How about: (apply vector :div.container (mapv #(vector (keyword (str "div." %)) %) ["first", "second", "third"])) The idea is to use apply to pass each element of the result of mapv as an individual argument to vector. As a bonus, apply admits other arguments before the collection argument, so we can...
The state in (prn state) is the component state. The atom data is the application state, which in your component you have called app. (om/root (fn [app owner] ; <- `app` is the application state (reify om/IInitState (init-state [_] (prn "(1) returning initial state now") {:text "Hello world!"}) om/IRenderState (render-state...
You can use (.getTime (js/Date.)) or you could also use now or epoch from cljs-time. ...
Here's the JavaScript that generates an object attached to the window. It has too properties. foo which is a function and .bar which is a string. (let [my-object (set! (.-myobj js/window (clj->js {}))) some-func (fn [] (+ 1 1))] (set! (.-foo my-object) some-func) (set! (.-bar my-object) "something")) ...
Daniel Kersten over at the ClojureScript Google Groups, explained to me why the code snippets weren't working. The link to the post is here. 1st code snippet reagent overrides clojure's atom with it's own implementation. re-frame's views.cljs doesn't refer to this by default. Once you refer to reagent's version of...
clojure,namespaces,clojurescript,reagent
You cannot do this dynamically, but as far as I can tell for your problem there isn't much need. ClojureScript macros can reflect back into the compiler - you could easily use the cljs.analyzer.api namespace to figure out which vars you need (through var metadata or whatever) and automatically emit...
React offers dangerouslySetInnerHTML as an option for its components. If you are using Sablono with Om you can do something like this: (om.dom/div #js {:dangerouslySetInnerHTML #js {:__html "<b>Bold!</b>"} nil) More info here: https://groups.google.com/forum/#!topic/clojurescript/DXzHx3vkszo https://github.com/r0man/sablono/issues/36...
clojure,functional-programming,clojurescript
The only sins here are Unnecessary quadratic complexity in state Evidence of floating point usage and error in your blog post. The code as written should be using ratios -- (state 2) should not terminate... Reduce/reduced would be a good candidate for your state function. (defn thomsons-lamp [] (map vector...
You can use get-node. There is an example available here. Note that the component must be already mounted in order to access its DOM element, therefore you should invoke get-node in one of the Om lifecycle methods that are invoked after the component is mounted (e.g. did-mount). ...
You can do this using macros executed at compile time. project.clj :dependencies [[org.clojure/clojure "1.6.0"] [org.clojure/clojurescript "0.0-2202"]] :source-paths ["src"] :cljsbuild {:builds [{:id "main" :source-paths ["src/cljs"] :compiler { :output-to "resources/main.js" :optimizations :whitespace :pretty-print true}}]}) src/cljstemplates/core.clj (ns cljstemplates.core (:require [clojure.java.io :refer (resource)])) (defmacro deftmpl "Read template from file in resources/" [symbol-name html-name] (let...
The function remove returns a sequence, not a vector. Your state went from {:buttons [{:id 1} {:id 2}]} to {:buttons ({:id 1})}. By using into after remove you solve your problems: (fn [buttons] (into [] (remove #(= button-id (:id %)) buttons)))) Note: I tried this with Chestnut and it seems...
I figured out a way. You can just call (js-keys (.getContext canvas "2d")) and that will list all functions and properties of the JavaScript object....
clojure,reactjs,clojurescript,hiccup,om
(map as-hiccup (parse-fragment "<h1>HELLO WORLD!</h1>")) generates [:h1 "HELLO WORLD!"]...
Bodil had an experimental Ring-inspired web server framework for ClojureScript on Node.js here: https://github.com/bodil/dogfort...
I think the node_repl.clj has an error. (require 'cljs.repl) ;;; (require 'cljs.build) ;; ERROR? (require 'cljs.build.api) ;; <-- Replaced (require 'cljs.repl.node) (cljs.build.api/build "src" {:main 'hello-world.core :output-to "out/main.js" :verbose true}) (cljs.repl/repl (cljs.repl.node/repl-env) :watch "src" :output-dir "out") Now everything seems to work fine. ...
macros,clojure,functional-programming,clojurescript
It would be easy enough to modify the source of memoize to do this. (defn memo-one [f] (let [mem (atom {})] (fn [& args] (if-let [e (find @mem args)] (val e) (let [ret (apply f args)] (reset! mem {args ret}) ret))))) (defn foo [x] (println "called foo") x) (def memo-foo...
web-applications,routing,clojurescript,om
Ok, I figured out what I needed. It seems pretty clean to me and works. For completeness, I would just need to add an on-page-load type listener that checks for the hash and a renderer that renders state changes to the hash. That should be pretty straight-forward (based on my...
(let [the-image (js/Image. 80 80)] (set! (.-src the-image) "foo.png") the-image ;;=> the full image is here with the src = foo.png ) ...
clojure,clojurescript,core.async
Keeping your current code structure, one way to do this is to add a mouse-up channel (or combine this with mouse-down into a mouse-buttons channel or something). Then in your go loop, use the following logic: Read from mouse-down and mouse-channel (using alt). If mouse-channel was read, ignore the value...
clojure,reactjs,clojurescript,chord,reagent
I agree with @myguidingstar that your problem is more about client-server synchronization than about clojure or reagent. You could have a similar problem, say, with GWT (been there, ...) Should I make another call to the server (a GET request) after the initial POST is successful? This could replace the...
Transit-cljs will handle all of these types automatically for you, you shouldn't need to do anything special to handle it when sending or receiving this. Transit is an alternate format to JSON for transferring representations of data. If you want to use Transit then your server will need to emit...
I got it working with .-currentTarget. See http://ckirkendall.github.io/enfocus-site/#doc-events and http://docs.closure-library.googlecode.com/git/class_goog_events_Event.html. (defaction change-src [selector src] [selector] (ef/set-attr :src src)) (defaction thumb-hover [] [".thumb"] (events/listen :mouseenter #(change-src "#full-image" (ef/from (.-currentTarget %) (ef/get-attr :src))))) ...
javascript,json,clojurescript,datomic,edn
Nothing against the jsedn project you mention, but it hasn't seen a commit in two years and has a couple long-standing issues/PR's that haven't been taken care of: I'd be weary of relying on it. You could easily acheive what you're after by creating a new clojurescript project and ^:export-ing...
clojure,read-eval-print-loop,clojurescript,om
A lot of the basics are covered in the ClojureScript wiki here. As of 2014 two popular browser REPLs are: Austin Weasel A simplified façade on top of Weasel is simple-brepl....
if-let is not applicable... The if-let macro is not applicable here. In an if-let, the result of the binding form is used as the test. It condenses code like (let [world (get-world ...)] (if world (do-something-with world) (do-something-else))) if, for example, get-world were to return nil when there was no...
When solving problems of this type, sometimes it's helpful to generate tree structure resembling the desired call tree at the REPL. Once the result looks all right, converting it to an actual call tree is generally straightforward. For example, here's a function to generate the om.dom/div call tree for your...
clojure,macros,conditional,clojurescript,reader
Yes, there is a way for a single file construction. (ns cljc.core #?(:cljs (:require-macros [cljc.core :refer [list-macro]]))) #?(:clj (defmacro list-macro [x y] ;; ... Assumedly one of the next CLJS compiler versions will do the import automatically....
emacs,clojure,clojurescript,slimerjs
Short version of the story: When the page loads, script is being connected using long polling to your ClojureScript REPL backend (for some REPLs web sockets are used instead). As soon as you do action in REPL, code is translated to JavaScript and sent to browser (via connection from step...
You need to specify an :asset-path in your compiled options (as the error message suggests). From https://github.com/clojure/clojurescript/wiki/Compiler-Options#asset-path When using :main it is often necessary to control where the entry point script attempts to load scripts from due to the configuration of the web server. :asset-path is a relative URL path...
leiningen,google-closure-compiler,clojurescript,google-closure
No. You can use closure-library in an uncompiled state, but you cannot directly exclude it without resorting to creating a new library which exports all of your methods. For related answers, see: http://stackoverflow.com/a/28281505/1211524 http://stackoverflow.com/a/10401030/1211524 ...
animation,clojure,clojurescript,core.async
It's common in CSP style programming to pass a control channel to event loops so you can, at the very least tell them when to stop. In this case if there was a control channel that went to main-animation-loop and you gave a copy of that to dance!, then dance...
Updating the clojurescript version seemed to fix my issues. So after changing [org.clojure/clojurescript "0.0-2665"] to [org.clojure/clojurescript "0.0-2740"] After loading the test file above into the REPL with C-c, C-k, (cemerick.cljs.test/test-ns 'cemerick.cljs.test.example) produced the expected output of {:test 1, :pass 1, :fail 0, :error 0} ...
There is a conceptual mismatch here. The js library already expects a defined behavior but you want to define it yourself from cljs. Should the listener be a js object with 2 methods, onConnection and onUpdate? Then you need some translator between your SubscriptionListener in cljs and a regular object...
events,dom,asynchronous,clojurescript
You are trying to stringify an Event Object. This is not a good idea, look at this answer: How to stringify event object? Try extracting the interesting information (i.e which key was pressed) and passing that as a value to the channel. To pass the whole Event Object and manipulating...
clojure,leiningen,clojurescript,lighttable
This is caused by the symbol unsigned-bit-shift-right being found in the clojure.core namespace as well as a cljs.core. The clojure.core namespace is compiled/loaded before cljs.core, and the introduction of the new symbol is throwing the warning. It looks like, from the namespace, you are writing clojurescript. If you look at...
In ClojureScript we have two special forms for interop with JavaScript: . and .-. . should be used to call methods of objects and .- should be used to access properties (including functions as a value). If you look at the source code of the value function in the Dommy...
markup,clojurescript,hiccup,reagent
Try escaping the quotes: [:p "\"I want quotes around this string\""] ...
You don't need to parse the HTML string. It's unnecessary overhead. React/Om supports something like DOM's innerHTML property. Just set the prop this way: (om.dom/div #js {:dangerouslySetInnerHTML #js {:__html "<b>Bold!</b>"}} nil) If you work with plain DOM without Om, set the innerHTML property like: (let [div (. js/document getElementById "elId")]...
This question is pretty old, but I'll give it a shot. I believe the main use-case for ref-cursors is to promote modularity and decoupling of the global application state from components. It limits the scope of components to just the data that they depend on, and nothing else. Normally, you'd...
A PersistentQueue is another persistent data structure with different behavior and performance characteristics when compared to list, vector, map, and set. If you look at the docstrings for pop and peek, for example, you will see this datatype being referred to as "queue". Since it has no literal syntax, you...
I think it's better to save only data in an atom and to generate the HTML as part of the component logic. Also it's better to trigger the AJAX call outside the render phase, for example, before the component will mount, or as the result of an event (on-click on...
You can either use an adjacency list or a recursive approach. Both approaches are discussed in more detail as answers to this very similar question....
Given the data you provided, you could try something like the following: (defn id->title [x] (->> titles (filter #(= (:id %) x)) first :title)) (defn format-data [structure] (clojure.walk/postwalk (fn [x] (if (map? x) (into [:ul] (map (fn [[k v]] (if (= v [:ul]) [:li (id->title k)] [:li (id->title k) v]))...
Ignoring the specifics on the syntax of requiring records, there are two main ways to write ns declarations (or any platform specific code) for multiple Clojure variants while sharing the majority of your code. CLJX is a Clojure preprocessor that runs before the Clojure compiler. You write platform specific code...
clojure,leiningen,clojurescript
The way your question is posted it is not very clear "why two projects?". It seems that you may be confusing different projects with different profiles, e.g. .. classpaths? In order to work with multiple lein projects at once, similar to the way you would work with master pom =>...
Because ClojureScript has access to all native JavaScript, we can use built-in JS functions like .indexOf. This makes it fairly simple to do things like: > (.indexOf "clojurescript" "scr") 7 As Joaquin noted, this also makes it very simple to determine the existence of a substring as well: > (not=...
javascript,clojure,clojurescript,om,reagent
The following would be the ClojureScript equivalent: (defn key-value [obj] (loop [acc [] ks (.keys js/Object obj)] (if (seq ks) (recur (conj acc (clj->js {(first ks) (aget obj (first ks))})) (rest ks)) (clj->js acc)))) or alternatively using reduce instead of loop/recur: (defn key-value [obj] (clj->js (reduce (fn [acc k] (conj...
javascript,ruby,clojure,clojurescript
Your Plan A is impossible to secure easily, because client-side results are generally not trustable. Your Plan B is a good plan. You are correct this puts the onus on your server. Server performance is a huge topic. Some tools you may want to look at as you grow: Memcache...
You have to think that clojurescript is a compiler to javascript as a language, not only browser JavaScript. You can also use it in other platforms like nodejs or with the QT library where NodeList does not exist (because it is part of the Dom api and not the standard...
I suspect this is a bug in ClojureScript. homepage.core> [(hash [2]) (hash (cljs.reader/read-string "[2]"))] [-1917711765 -1917711765] homepage.core> [(hash [0]) (hash (cljs.reader/read-string "[0]"))] [965192274 965192274] homepage.core> [(hash []) (hash (cljs.reader/read-string "[]"))] [0 -2017569654] homepage.core> [(hash {}) (hash (cljs.reader/read-string "{}"))] [-15128758 -15128758] homepage.core> [(hash #{}) (hash (cljs.reader/read-string "#{}"))] [0 0] homepage.core> *clojurescript-version*...
javascript,clojurescript,compojure,ring,cljsbuild
The compiler is optimized for generating one file per app. You could use multiple builds to do something like what you want, but you would have common code and blobs in both pages (builds), which is not optimal.
This is a parser error, there are three ways to make this work, creating a var with the number and calling .toString on that, writing the number with an extra a dot or writing the number in parentheses. If you try 6.toString(2) on a JavaScript console you will get this...
clojurescript,om,hiccup,reagent
The whole repo is here and it works. I added the parsing from style tag to a map for React in the core.cljs file: (ns hickory-stack.core (:require [clojure.string :as s] [clojure.walk :as w] [reagent.core :as reagent :refer [atom]] [hickory.core :as h])) (enable-console-print!) (defn string->tokens "Takes a string with syles and...
javascript,clojure,clojurescript
Use this-as macro ! How ever def is not nice inside macro... use let if possible ! (this-as t (let [item (.getItems t)] ..... Remove parenthesia around base, (it's function call, and you don't want to call), now this...
(Long answer :P) Even though Clojure and ClojureScript share a good amount of features, there are some that are specific to one or the other. For example there are no real classes in JavaScript so the :gen-class specification in the ns form doesn't make much sense. One important fact is...
If you want to import the Closure classes, you use import, if you are importing functions or vars, then you use require or use: (ns async-tut1.core (:require [goog.events :refer [listen] :as ev]) (:import [goog.net XhrIo])) What it means is that the import form is specific to the use case of...
The protocol methods om/IWillMount and om/IWillUnmount are only invoked once when the component is mounted/unmounted. It is not invoked on every render and therefore a log message will not be produced when you click the '+' button if it does not result in a component being mounted/unmounted. The use of...
javascript,clojure,clojurescript,lighttable
[object Object] is the default string representation of Javascript objects. Unfortunately JS objects are much more opaque than the Clojure(script) data structures. There are several ways to improve the situation but none of them is prefect. You can overwrite the toString() method for the object or its prototype and return...
clojure,reactjs,clojurescript,cursors,om
You want to call your comments function and use its return value (the cursor), not use the function itself. Change this line: (let [foo (->> comments)] to: (let [foo (->> (comments))] and that should work for you....
You need to add your javascript file to the html file that you want to use it on. So if you have two different html files index and about you will need two different cljs files. Both of them will contain a method to initialize the js like this (defn...