clojurescript

Implementing an ajax call in clojurescript

北慕城南 提交于 2019-12-03 11:21:54
问题 I'm new to clojurescript and would like to do a deeper dive by implementing a previously written application purely in clojurescript, but am at a loss with respect to to implement an ajax call. Can anyone point me to an example online or provide me with a code snippet or two? 回答1: January 22, 2016 update Although it still works, the original answer is from a time when there was a general lack of ClojureScript solutions with more than 1 contributor. Rather than leveraging XhrIo directly,

Why clojurescript macros can't be written in clojurescript?

冷暖自知 提交于 2019-12-03 10:26:42
While clojure and clojurescript features are basically the same (apart from obvious differences), macros are not. When I want a macro in clojurescript I have to write it in clojure and require it with require-macros. Is that a technical limitation of javascript or just a design decision? Why can't both be the same? From ClojureScript: Up and Running by Stuart Sierra and Luker VanderHart, page 69: Macros are applied during the compilation process. They do not exist at runtime. Because the ClojureScript compiler is implemented in Clojure, ClojureScript macros must be written in Clojure, not

use predefine react component from reagent?

混江龙づ霸主 提交于 2019-12-03 09:34:34
问题 I have some external UI with abstraction of react components and I want to reuse them from reagent, is there any way to directly render predefined react component just by passing data from clojurescript. I am a clojurescript beginner. 回答1: Let's try! We can start by writing the component in a js file. var CommentBox = React.createClass({displayName: 'CommentBox', render: function() { return ( React.createElement('div', {className: "commentBox"}, this.props.comment ) ); } }); Then we can call

How to filter vector of maps by multiple keys in Clojure

让人想犯罪 __ 提交于 2019-12-03 09:15:32
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)) (lower-case (:first-name %))) @data)) > (my-filter "John1") > ({:last-name "Dow1", :age "14", :first

Which is faster, Clojure or ClojureScript (and why)?

孤人 提交于 2019-12-03 07:04:21
问题 If I had to guess, I'm pretty sure the answer is Clojure, but I'm not sure why. Logically (to me) it seems like ClojureScript should be faster: Both are "dynamic", but ClojureScript Compiles to JavaScript, running on V8 V8 engine is arguably the fastest dynamic language engine there is V8 is written in C whereas Clojure: Is also dynamic Runs in JVM, which has no built-in dynamic support, so I'm thinking thus JVM has to do whatever V8 is doing too, to enable dynamic support and Java is slower

Clojurescript interoperability with JavaScript

风格不统一 提交于 2019-12-03 06:13:40
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. Francis Avila Clojurescript vars, functions, and deftypes/records are normal JS vars, functions, and constructor functions

How do I create a json in clojurescript

那年仲夏 提交于 2019-12-03 04:43:44
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 objects. Or a way to create a new javascript object and then set properties on it? Just for the sake of

ClojureScript interop

微笑、不失礼 提交于 2019-12-03 02:17:36
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] 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 indicating a js map. cljs.user> (def foo (clj->js {:bar 100})) #js {:bar 100} cljs.user> (.-bar foo) 100 cljs.user>

Implementing an ajax call in clojurescript

那年仲夏 提交于 2019-12-03 01:49:38
I'm new to clojurescript and would like to do a deeper dive by implementing a previously written application purely in clojurescript, but am at a loss with respect to to implement an ajax call. Can anyone point me to an example online or provide me with a code snippet or two? January 22, 2016 update Although it still works, the original answer is from a time when there was a general lack of ClojureScript solutions with more than 1 contributor. Rather than leveraging XhrIo directly, definitely consider using a well-maintained, feature-rich solution that wrappers it instead like cljs-ajax , as

Server push of data from Clojure to ClojureScript

天大地大妈咪最大 提交于 2019-12-03 01:11:46
I'm writing an application server in Clojure that will use ClojureScript on the client. I'd like to find an efficient, idiomatic way to push data from the server to the client as realtime events, ideally using a some combination of: http-kit core.async Ring (But I'm open to other possibilities) Can anyone provide a good example / approach to doing this? I prefer to use aleph , here is the wiki , you can simply use wrap-ring-handler function to wrap existed handlers. For the 'push' function, most useful part is aleph's async handler. It builds on top of netty, not a one connection one thread