clojurescript

How do I add my own JavaScript libs to ClojureScript?

我与影子孤独终老i 提交于 2019-12-04 01:21:59
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), but so far without luck: Exception in thread "main" java.lang.IllegalArgumentException: No implementation

Accessing “this” in Clojurescript

99封情书 提交于 2019-12-03 23:47:22
问题 Is there a way to access the "this" object in clojurescript? I am having issues with event propagation when I wrap an icon with an anchor and try to attach a handlder to the anchor. Without access to "this" in the handler I am constantly dealing with the inner icon firing the event sometimes and the anchor firing other times. edit: As was suggested below, this-as is the way to do this. An example could be (defn my-handler [e] (this-as this (let [data-attr (.data ($ this) "my-attr")] (log data

How to dynamically change page title and description in ClojureScript / Reagent

牧云@^-^@ 提交于 2019-12-03 20:57:36
Is there a simple way to change document title and description (or other [:html [:head [:meta tags) from ClojureScript Reagent application? For example on every bidi route match change the title and description to match the new page content. Preferably this should work without using js/window so that the same code can be used in a browser as well as in server isomorphic pre-rendering (which I need for SEO). In the JavaScript/React world there are react-document-meta and react-side-effect which can probably be converted to Reagent components. But this way of handling side effects seems like a

Clojurescript interoperability with JavaScript

て烟熏妆下的殇ゞ 提交于 2019-12-03 17:28:38
问题 I have built an application using mostly Angular. Now I'd like to transition the project to Clojurescript. Clojurescript has very nice interop with JavaScript as we all know but is it feasible to do the other way around? How can regular JavaScript /Angular code tap into the JavaScript generated from Clojurescript ? The dream would be to write new features in clojurescript and have them work side by side with the legacy code. Any tips or tricks regarding this are welcome. 回答1: Clojurescript

How to author agnostic JavaScript library in ClojureScript?

為{幸葍}努か 提交于 2019-12-03 15:44:23
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 issue: no index.js (it's called main like in Java), no module.exports = blah blah . Seems like it's

How do I create a json in clojurescript

狂风中的少年 提交于 2019-12-03 15:03:40
问题 I have some clojurescript that I want to interop with some javascript libraries. In my clojurescript code I do some analysis and come up with a list of maps. something like [{:prop1 "value1" :prop2 "value2"}, {:prop1 "something else" :prop2 "etc"}...] I need to pass this to a javascript functions as [{prop1: "value1", prop2: "value2}, {..} ...] I'm not sure how to return a javascript object form my clojurescript function though. Is there a way to serialize nested maps and lists to javascript

Define my own reader macro in clojure

不想你离开。 提交于 2019-12-03 12:47:42
I would like to define my own reader macro in clojure: (read-string "ßfoo") => (some_func :foo) Is it possible? 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 #ß foo will return "some-func invoked with :foo" This technique is described here: The reader: Tagged literals

ClojureScript - convert arbitrary JavaScript object to Clojure Script map

蓝咒 提交于 2019-12-03 12:19:56
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 " x options))) Yields an error when loading my code : Uncaught TypeError: Cannot read property 'prototype

js/console.log in ClojureScript

我怕爱的太早我们不能终老 提交于 2019-12-03 12:13:38
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 ? Joaquin 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 it is possible that it has been deprecated in newer versions of the compiler. Which version are you

ClojureScript interop

一曲冷凌霜 提交于 2019-12-03 11:53:23
问题 I am trying to find out how to access Javascript objects properties in ClojureScript. If I know in advance the name of the property, that is easy. To get foo.bar I just do (.-bar foo) Is there a way to access a property whose name is known only at runtime? I am looking for the equivalent of the JS syntax foo[dynamicBar] 回答1: You can use aget / aset to access properties known only at runtime. ;; Use clj->js to convert clj(s) map to javascript. ;; Note the #js {:bar 100} reader literal