Menu
  • HOME
  • TAGS

ClojureScript REPL in emacs printing out extra ^Ms and nils

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...

Evaluate a list of functions in Clojure

clojure,functional-programming,clojurescript

(map #(% arg) function-list) Should do the job?...

Conditionally Add a Class to an Element with Om

reactjs,clojurescript,om

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...

Instantiate namespaced javascript class

clojurescript

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) ...

How do I use 'this-as' in ClojureScript?

jquery,clojurescript

Okay, got it. Here's an example: (bind ($ "selection") "click" (this-as somename (js/alert somename))) ...

Clojurescript, how to access a map within a indexed sequence

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...

Idiomatic way to select a map in vector by a key

clojure,clojurescript

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) ...

How to invoke .toDateString() on Date object in Clojurescript

javascript,clojure,clojurescript,om,reagent

(.toDateString (js/Date. 1420971497471)) ...

transact app-state in will-mount has no effect

clojurescript,om

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...

How to firebase.push in Clojurescript? Is my data correct?

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...

Find if a map contains multiple keys

clojure,clojurescript

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...

Is there any way to make an onClick handler in Om without using anonymous function?

clojurescript,om

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...

Which is the more idiomatic method in ClojureScript for printing to the console?

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...

ReferenceError: “goog” is not defined when running lein cljsbuild

leiningen,clojurescript

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....

Process infinite sequence with delay

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...

How can I reduce the size of my ns declaration in Clojurescript?

clojurescript

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...

How to connect fireplace.vim to browser repl

vim,clojurescript

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...

Reagent :component-did-mount

reactjs,clojurescript,reagent

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"}]])) ...

In Clojure how can I merge two vectors of maps?

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?...

ClojureScript/Om: Rendered HTML is missing attributes

clojure,clojurescript,om

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....

Loop in clojure with or condition

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]) ;...

Reagent does not register atom watch

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]] ...

Creating a clojurescript atom that runs on a heartbeat

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))))))) ...

Is it possible to call a ClojureScript module from a jQuery or AngularJS normal webapp?

clojurescript

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...

clojurescript iterate over the keys of an object

clojurescript

The answer was to use goog.object.forEach: (defn clone-object [key obj] (goog.object/forEach obj (fn [val key obj] (log/debug key)))) ...

Target-dependent macros with cljx

clojure,clojurescript,cljx

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)) ...

on-click handler for a list item reagent clojurescript

clojure,clojurescript,reagent

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...

Clojurescript : two dots in expression

clojurescript

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)...

How to integrate figwheel with ring server to get back-end auto-reload?

clojure,clojurescript,ring

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...

cljs is not defined in LightTable

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.....

Using inline style string with ClojureScript, Om, and React.js

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"}) ...

Clojure opposite of reduce?

clojure,clojurescript

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...

Om/Clojurescript: Issue rendering a reset application state

clojurescript,om

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...

How do you get a timestamp in ClojureScript?

clojurescript

You can use (.getTime (js/Date.)) or you could also use now or epoch from cljs-time. ...

How can I create a global object, and attach a string and a function to that object, in ClojureScript?

clojure,clojurescript

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")) ...

re-frame: Input :on-change reset! doesn't change input value

clojurescript,reagent

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...

Enumerate namespaces and dynamically load them in ClojureScript

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...

Render unstanitized HTML with ClojureScript+Sablono

reactjs,clojurescript,om

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...

More functional way to do this?

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...

How can I get the DOM element from an Om DIV?

clojurescript,om

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). ...

Clojurescript templating from html files

clojurescript

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...

Having trouble correctly manipulating state in Om app

clojurescript,om

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...

How to list the properties and functions of a JavaScript object in ClojureScript?

clojurescript

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....

How to use Hickory with Clojurescript (OM/Reagent)?

clojure,reactjs,clojurescript,hiccup,om

(map as-hiccup (parse-fragment "<h1>HELLO WORLD!</h1>")) generates [:h1 "HELLO WORLD!"]...

Clojurescript on Heroku

node.js,heroku,clojurescript

Bodil had an experimental Ring-inspired web server framework for ClojureScript on Node.js here: https://github.com/bodil/dogfort...

ClojureScript Node.js REPL issue

npm,clojurescript

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. ...

Function/macro to execute function body only when arguments changed from last call

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...

ClojureScript & Om: Best practice for writing document.hash

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...

How to set JS Object Parameter whilst returning the JS Object

clojurescript

(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 ) ...

clojurescript core.async - tell if mouse is down while mouseover

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...

Keeping Client State Up-To-Date In Reagent / Clojurescript

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 reader handler to read in array

node.js,clojurescript,transit

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...

Enfocus swap img src to $(this).attr('src')

clojurescript

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))))) ...

Client-side transform EDN to JSON (Datomic data consumed by HTML5 app)

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...

How do I start a repl inside of a ClojureScript page?

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....

clojure - if-let syntax

clojure,clojurescript

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...

Using Om, Generate Nested divs From a Nested Map

clojure,clojurescript,om

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...

can cljc single-file macro definitions to work with clojurescript?

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....

How does the ClojureScript REPL via austin interact with SlimerJS and the Browser-REPL?

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...

How to serve clojurescript over flask

python,flask,clojurescript

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...

Compile ClojureScript excluding Closure Library from Artifact

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 ...

How to prevent overlapping animations using core.async?

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...

Null pointer exception/reference error when trying to use clojurescript.test

emacs,clojure,clojurescript

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} ...

Using defprotocol to create javascript object

clojurescript

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...

How to transfer html dom event through clojurescript channel

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 console spits out 'unsigned-bit-shift-right' warning on simple HelloWorld

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...

Find value of input element

clojurescript

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...

Hiccup: How can I render a quotation mark in Reagent?

markup,clojurescript,hiccup,reagent

Try escaping the quotes: [:p "\"I want quotes around this string\""] ...

How to turn text into DOM elements using Clojurescript? (And Om?)

clojurescript,om

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")]...

Passing App Atom vs Ref-Cursors in Om

clojurescript,om

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...

How can I use the Clojurescript cljs.core.PersistentQueue queue?

clojurescript

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...

Ajax GET with Reagent

ajax,clojurescript,reagent

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...

Convert vector of maps to a tree

clojurescript

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....

Combining Two clojure.walk/postwalk Calls Into One

clojure,clojurescript

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]))...

Import Record Type in Clojure/ClojureScript

clojure,clojurescript

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...

Working on a multiple leiningen project

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 =>...

Index of a substring in ClojureScript

string,clojurescript

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=...

How to loop a JavaScript object and push each into an array, in Clojurescript

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...

Online Betting Games and Security: How to?

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...

Why aren't NodeList / HtmlCollection seqable?

clojurescript

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...

hash function behaves different with empty vector in clojure and clojurescript

hash,clojure,clojurescript

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*...

Specify the ClojureScript file I want to include

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.

Retrieve binary representation of number in ClojureScript

javascript,clojurescript

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...

How to convert HTML tag with style to Hiccup? React problems

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...

How do I call Javascript from Clojurescript?

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...

Hello World - Clojurescript

clojure,clojurescript

(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...

Clojurescript and Google Closure: How to correctly require a namespace or import a class?

clojurescript

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...

What is the difference between using defmulti and defn as a function of om/build-all?

clojure,clojurescript,om

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...

Let LightTable show javascript object details

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...

om ClojureScript ref-cursor error when trying to update vector using om/transact

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....

Clojurescript OM targeting element on different html

clojure,clojurescript,om

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...