This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-10
Channels
- # beginners (15)
- # boot (15)
- # cider (6)
- # cljs-dev (231)
- # cljsjs (1)
- # cljsrn (26)
- # clojure (147)
- # clojure-argentina (1)
- # clojure-dev (8)
- # clojure-germany (1)
- # clojure-italy (26)
- # clojure-russia (2)
- # clojure-spec (83)
- # clojure-uk (154)
- # clojurescript (123)
- # conf-proposals (3)
- # core-async (5)
- # cursive (26)
- # datascript (21)
- # datomic (120)
- # emacs (2)
- # graphql (9)
- # hoplon (195)
- # instaparse (16)
- # jobs-discuss (1)
- # leiningen (8)
- # luminus (8)
- # lumo (7)
- # off-topic (17)
- # om (7)
- # om-next (3)
- # parinfer (121)
- # pedestal (5)
- # planck (13)
- # re-frame (11)
- # reagent (21)
- # ring-swagger (2)
- # spacemacs (28)
- # uncomplicate (3)
- # unrepl (7)
- # untangled (34)
- # vim (5)
Is there a way to get response status out of cljs-ajax? I can't figure out how to get anything more than [[ok response]]
which is just a true/false flag. The response object is just the body, not the whole response. Anyway to get the whole response instead?
tjscollins:
(-> (ajax/json-response-format)
(update :read (fn [original-handler]
(fn [response-obj]
{:headers #?(:cljs (js->clj (.getResponseHeaders x))
:clj (reduce (fn [headers header]
(assoc headers (.getName header) (.getValue header))) {} (-> x :response .getAllHeaders)))
:body (original-handler response-obj)
:status #?(:cljs (.getStatus response-obj)
:clj (-> response-obj :response .getStatusLine .getStatusCode))}))))
Thanks. This is a better option than the other one I just found, which was :response-format {:read identity :description "raw"}
, which works, but then you still have to use .getStatus, etc. on the result.
anyone here use sente
for websockets? (
I have a security concern but I'm too much of a clojure noob to entirely understand this aspect of it
;; server
(defmethod -event-msg-handler
:default ; Default/fallback case (no other matching handler)
[{:as ev-msg :keys [event id ?data ring-req ?reply-fn send-fn]}]
(let [session (:session ring-req)
uid (:uid session)]
(debugf "Unhandled event0: %s" event)
(when ?reply-fn
(?reply-fn {:umatched-event-as-echoed-from-from-server event})))) ;; <---- this is the part that concerns me (see below)
;; client
(when-let [target-el (.getElementById js/document "btn2")]
(.addEventListener target-el "click"
(fn [ev]
(->output! "Button 2 was clicked (will receive reply from server)")
(chsk-send!
[:example/button2 {:had-a-callback? "indeed"}]
5000
(fn [cb-reply] ;; <---- it looks like this function is being sent to server to be executed as ?reply-fn
(->output! "Callback reply: %s" cb-reply))))))
I'm sure there's something I don't understand but it looks as if arbitrary code is being sent to be executed on the server...
@goomba: the code is not sent for execution on the server. all the ?reply-fn
will do when called is send its arguments to the client for execution there
:thinking_face:
you can try writing a callback that is not even valid clojure (only valid clojurescript)
ok so in this case
or writing one that modifies the DOM, prints to the browser console, or does anything else that doesn't make sense in the server side
?reply-fn
is sending back to the client {:umatched-event-as-echoed-from-from-server event}
which is executed by the anonymous function
(fn [cb-reply]
(->output! "Callback reply: %s" cb-reply))
?okay... that makes sense with the behavior I'm seeing, thank you
I see... THANK you
I was gonna š if I couldn't use this! Yes, sente is awesome!!!
If somebody has a minute to take a look please š https://stackoverflow.com/questions/45003533/how-to-use-bignumber-js-with-clojurescripts-npm-deps-feature
@madvas just looks like the module is written in a format that Closure canāt understand
what is the cljs way to have a function that is: 1. called once every 100 ms 2. across different reloads (via figwheel / boot-reload), don't have the function end up being called too much
(defonce interval
(js/setInterval (fn [] ...) 100))
it'll look something like:
(defn r-timer-new []
(let [r (r-atom (js/Date.))
update (fn []
(reset! r (js/Date.)))]
(js/setInterval update 100)))
js/clearInterval
?
[it's a bit different from the original qu3estin . asked; but across reloads, I may end up creating ew timers ]
@rauh @skapadia afaik they use core.async under the hood, one should be aware that it produces a lot of code
promesa requires you to do p/await
inside p/alet
, which, in some sense, defeats itās purpose š
@skammer you could use js*
macro to implement something like this i cljs
(defmacro async [body]
`(js* "(async function() {~{}})();" ~body))
(defmacro await [expr]
`(js* "await ~{}" ~expr))
(async
(let [a (await 1)
b (await 2)]
(+ a b)))
but Iām not sure if this is safe
@skammer yeah, this wouldnāt JUST work. for example let
bindings is being wrapped into IIFE which also have to by async
function in order to be able to use await
inside of it
in any case, unless you are targeting browsers that have native support for async/await
, thereās not much benefit since both core.async
and transpiled async/await
produce a lot of code
Iām targeting nodejs, so even large amount of generated code isnāt really an issue here
@skammer In that case I'd def take another look at promesa, bluebird is faster than native async/await.
I'm trying to flip the state of an item in an atom, but I cant get it to work
(defn todo-item [{:keys [title done]}]
[:li (done? done) " - " title
[:a {:on-click #(reset! not :done)} done]])
@shidima_ Use
swap!
instead of reset!
to change one key of the map. Assuming that the atom is called state use (swap! state #(assoc % :done (not (:done %))))
or more concisely (swap! state update :done not)
Hello developers. I'm new to the ClojureScript language, and it's a pleasure to be yours.
I am currently learning to create mobile apps using clojurescript
, react-native
and I would add a toobar in my app. help please
335/5000 I would like to create a registration form with
ClojureScript
using React-Native
(and Reagent
thereafter). And I would like to include the different components with MaterialDesign, and I do not know how to do it. Do you have any suggestions? I have already found on the Internet, but I did not have much.I just want to create a simple registration form, using ClojureScript
MaterialDesign
ReactNative
.
Hi all, How can I pass a function as an argument as follows: I need a button component with the ability to add or subtract from a value so would like to have (defn MyBtn [operator] [:button {on-click (operator valA valB)} str opertor])
and call it as [MyBtn +]
or [MyBtn -
] etc. Hope that makes sense! Thx!
@fedreg {:on-click (fn [event] (operator valA valB)}}
is what you want for the handler
@dnolen Thx! My example wasnāt the best. I had the fn [e]
part but was calling the operator incorrectly within my swap!
function. Got it though. Thx again!
re: async/await
support, Iām curious as to why people want this ⦠why not just patch Promises to be channels?
one reason may be to be able to translate async/await library examples to clojurescript: https://github.com/zeit/micro#async--await
@devth I wanted that many times, even a stupid one
i guess all the mutability in js makes that hard
shouldnāt be hard to print a JavaScript AST to ClojureScript
but.. ^ famous last words, right?
often need to grab a snippet from somewhere and translate. e.g. https://github.com/GoogleCloudPlatform/stackdriver-errors-js#initialization
this might help with translating js async/await examples - http://funcool.github.io/promesa/latest/#async-await-syntax
would be a great web service, like http://htmltohiccup.herokuapp.com/
Any reviews for this book? Half off for DRM day and just wondering if anyone has experience with it https://www.packtpub.com/web-development/learning-clojurescript
Hey everyone, Iām trying to follow along with the modern-cljs tutorials but Iām running into issues with boot-cljs-repl
boot.user=> (start-repl)
<< started Weasel server on ws://127.0.0.1:50549 >>
<< waiting for client to connect ... Connection is
Writing boot_cljs_repl.cljs...
Iām trying to connect to the nrepl server but the boot repl
is just hanging here. Any ideas as to whatās going on?did you open the page in the browser?
do you see any errors in the dev console?
It also shows that Connection is ws://...
instantly even if i donāt have localhost:3000
open
can you verify if the browser connects via websocket?
you may need to add code to that effect, maybe you skipped over that part of the tutorial?
ah wait boot-cljs ads that
try shift-reloading the browser
anyway thanks a bunch @pesterhazy
sure thing
@benbot you probably use Chrome? Then you ran into this recent change in how Chrome caches javascript files when you click Reload: https://blog.chromium.org/2017/01/reload-reloaded-faster-and-leaner-page_26.html
Chrome essentially caches js files served without Cache headers forever, even if you click reload.
Reloading is faster if you don't actually reload anything.
Hi everyone, I have a question and I would like to know if anyone here can help me. What is the best way to via spec using date and time fields.. Iām using this way:
(s/def :model.shift/initial-date #(instance? goog.date.UtcDateTime %))
(s/def :model.shift/start-time #(instance? goog.date.DateTime %))
(s/def :model.shift/end-time #(instance? goog.date.DateTime %))
And how could I use exercise with this fields?So I am new to macros and found a nice use case for one, however, I don't think it's quite right. My goal is to be able thread js/requestAnimationFrame through a list of functions. This is my macro:
(defmacro do-raf
[& functions]
(list (reduce (fn [val# item#]
(list `fn `[] item# (list `js/requestAnimationFrame val#)))
`(fn [])
(reverse functions))))
This is what a macroexpand looks like (macroexpand '(do-raf
(aset _element "style" "opacity" 0)
(add-class! _element "set-html-transition")
(aset _element "style" "opacity" 1)))
((clojure.core/fn []
(aset _element "style" "opacity" 0)
(js/requestAnimationFrame
(clojure.core/fn []
(add-class! _element "set-html-transition")
(js/requestAnimationFrame
(clojure.core/fn []
(aset _element "style" "opacity" 1)
(js/requestAnimationFrame (clojure.core/fn []))))))))
When using the macro itself, it doesn't transition correctly. But, when I copy and paste the code generated by macroexpand it works as intended.isn't there an extra parenthesis around the whole thing?
Oh so I figured it out... Had to use the correct syntax for macros in a namespace desclaration
man I have problems and I've tried slack and IRC and nobody even answers ever
I have an om.next app going and I am trying to introduce some ready-made components, namely bootstrap by am using racehub/om-bootstrap
and as soon as I introduce that, it breaks the whole project
I've tried #clojurescript IRC, #om.next slack, #om slack and nothing
nobody speaks for hours
when I go to #rust IRC I get at least an attempt at answer in 5 minutes
Well I tried adding dependecy [racehub/om-bootstrap "0.6.1"]
and then I replaced om.dom/button with om-bootstrap.button/button
and I get the following console errors: Uncaught TypeError: Cannot read property 'prototype' of undefined
at core.cljs and at schema.cljs and at mixins.js and at util.cljs and at button.js
5 files, same error
just wondering if anyone has any om.next project using om-bootstrap on github to demonstrate proper use
First sneak preview post on the next major release - https://clojurescript.org/news/2017-07-10-code-splitting
is there some sort of schemata + cljs problem going on that I'm not aware of
@roklenarcic I have no experience with om-bootstrap
myself, but I find github search to be quite good to find examples on how to use something. See:
https://github.com/search?l=Clojure&q=racehub%2Fom-bootstrap&type=Code&utf8=ā
0 hits on code?