clojurescript

What should an om component return to render nothing?

我怕爱的太早我们不能终老 提交于 2019-12-22 07:50:11
问题 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

Clojurescript libraries - goog.require could not find

£可爱£侵袭症+ 提交于 2019-12-22 05:29:17
问题 New to clojurescript, and working through the "Modern CLJS" tutorial here. It instructs to pull in domina by adding it to the project.clj : :dependencies [[org.clojure/clojure "1.4.0"] [compojure "1.1.5"] [domina "1.0.0"]] And then use it in your script by referencing it in the ns form (ns cljstut.login (:use [domina :only [by-id value]])) However, when I actually run this in a browser, I see the following in the console log. goog.require could not find: domina Seems like I'm missing some

Enumerate namespaces and dynamically load them in ClojureScript

感情迁移 提交于 2019-12-21 18:02:42
问题 This may actually be a bit of an XY-problem, so I'll try to explain what the goal is first. I'm building a ClojureScript application which is composed of a set of Reagent components. It provides a user interface where you can dynamically add or remove UI elements. These UI elements (components) have a certain type. For example a Markdown component is-a Text component. Whenever the user is presented with the option to add Text we list all the components that match the type+descendants (in this

How to filter a list based on user input with ClojureScript and Om?

大憨熊 提交于 2019-12-21 12:18:56
问题 I just started to use Om (a reactjs based library for ClojureScript). I would like to filter a list based on user input. The following works but the solution seems to be to complicated. Is there a better one ? (ns om-tut.core (:require-macros [cljs.core.async.macros :refer [go]]) (:require [om.core :as om :include-macros true] [om.dom :as dom :include-macros true] [clojure.string :as string])) (enable-console-print!) (def app-state (atom {:list ["Lion" "Zebra" "Buffalo" "Antelope"]})) (defn

How do I add my own JavaScript libs to ClojureScript?

雨燕双飞 提交于 2019-12-21 09:06:12
问题 I want to write a Google Chrome extension, using ClojureScript. With ClojureScript I can use all the Google Closure libs, but afaik access to the Chrome browser is not included in those libs. So I want to wrap all the Chrome stuff in my own JavaScript lib. So far I tried creating my own jar that has a single JavaScript file that just creates a Foo object and exports the constructor. I'v added this jar to the lib directory of the ClojureScript compiler (which also has for example goog.jar),

How to author agnostic JavaScript library in ClojureScript?

依然范特西╮ 提交于 2019-12-21 04:57:30
问题 Let's say I have a cljs file containing the following: (ns foo) (defn add [x y] (+ x y)) and wish to make this available as a JavaScript library to non-ClojureScript devs (primarily focused on node.js). I can do this: clj -m cljs.main -c foo But the problem is that the output is geared towards google closure's module system (e.g. goog.require ). I can set the target to none with the -t flag (as opposed to browser or node), and that... doesn't fix this. Setting it to node also doesn't fix the

Define my own reader macro in clojure

大憨熊 提交于 2019-12-21 04:14:50
问题 I would like to define my own reader macro in clojure: (read-string "ßfoo") => (some_func :foo) Is it possible? 回答1: It is possible to create tagged literals by having a reader map in data_readers.clj at the top of your classpath. This must be in data_readers.clj at the top of your classpath (usually src directory). {ß reader-demo.core/read-fn} This goes into reader-demo.core (defn some-func [arg] (str "some-func invoked with " arg)) (defn read-fn [arg] (-> arg keyword some-func)) Invoking #ß

js/console.log in ClojureScript

若如初见. 提交于 2019-12-21 04:04:06
问题 I want to implement a function with ClojureScript to simplify js/console.log like this: (defn log [& args] (apply js/console.log args)) Calling it : (log "foo" "bar") throws: TypeError: Illegal invocation but this works : (js/console.log "foo" "bar") What is the problem ? 回答1: js/something is for accessing a js object, but you shouldnt nest dots after that, since it is not clojure compatible syntax and it was going to be removed. In older versions of the compiler (2138) your code works, but

ClojureScript - convert arbitrary JavaScript object to Clojure Script map

爷,独闯天下 提交于 2019-12-21 03:56:08
问题 I am trying to convert a Javascript object to a Clojure. However, I get the following error : (js/console.log (js->clj e)) ;; has no effect (pprint (js->clj e)) ;; No protocol method IWriter.-write defined for type object: [object Geoposition] Yes, this object comes from the Geolocation API. I suppose that I have to extend IEncodeClojure and IWriter , but I have no clue how. For instance adding the following : (extend-protocol IEncodeClojure Coordinates (-js->clj [x options] (println "HERE "

How to filter vector of maps by multiple keys in Clojure

我与影子孤独终老i 提交于 2019-12-21 03:03:06
问题 Assume we have a datastructure like this one: (def data (atom [{:id 1 :first-name "John1" :last-name "Dow1" :age "14"} {:id 2 :first-name "John2" :last-name "Dow2" :age "54"} {:id 3 :first-name "John3" :last-name "Dow3" :age "34"} {:id 4 :first-name "John4" :last-name "Dow4" :age "12"} {:id 5 :first-name "John5" :last-name "Dow5" :age "24"}])) I have learned how to filter it by one key, for example: (defn my-filter [str-input] (filter #(re-find (->> (str str-input) (lower-case) (re-pattern))