This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-19
Channels
- # beginners (34)
- # boot (111)
- # cider (37)
- # clara (57)
- # cljsjs (1)
- # cljsrn (22)
- # clojure (156)
- # clojure-austin (2)
- # clojure-mke (7)
- # clojure-russia (9)
- # clojure-spec (221)
- # clojure-uk (47)
- # clojurescript (42)
- # code-reviews (4)
- # community-development (9)
- # core-async (3)
- # cursive (50)
- # datomic (81)
- # emacs (12)
- # events (5)
- # hoplon (1)
- # jobs (2)
- # lein-figwheel (4)
- # leiningen (1)
- # luminus (3)
- # mount (2)
- # off-topic (1)
- # om (94)
- # om-next (3)
- # onyx (33)
- # re-frame (23)
- # reagent (41)
- # remote-jobs (9)
- # rum (30)
- # slack-help (2)
- # specter (1)
- # untangled (20)
- # yada (17)
btw, I've moved to cljs.http and I think I understand its flow, e.g.:
1. cljs-http request returns a core.async channel (don't know what a channel is, but I'm thinking it's a response object)
2. that channel contains a success or failed response (still thinking this is a JS object, same what you receive if you do AJAX in JS)
3. we can read that channel response using the <!
keyword that must be inside a go
block
... so here's my attempt, however, I get a blank page:
[text (str (:status (go (<! (http/get "")))))])
nope, it wouldn’t work as essentially it will be like [text (str (:status ChannelObject#2123)))]
Inside go macro you can do blocking and so on, but for outside code go block will be evaluated into new channel object
Can you use anything simpler but core.async? It’s nice but overkill for making just HTTP calls and requires some learning. But actually in any case you have to invert logic - do async HTTP IO and once it’s done do (re) rendering
thanks @artemyarulin, tbh, I don't even know what to use, someone suggested this so I tried it, but since it uses core.async, it brought me another layer that I basically don't even understand just to fetch a json data from a web server
ok, this one returns an [Object] [Object]
:
[text (str (go (let [response (<! (http/get ""))]
(:status response)
(map :login (:body response)))))])
@ejelome This isn't the best option, but maybe to get something temporarily working, you could use a blocking take <!!
.
[text (str (:status (<!! (http/get ""))))]
there is no blocking read in CLJS as far as I know
because there is no blocking IO in JS 🙂
@ejelome The double bang implies that it's a blocking operation that can be used outside of a go block. https://clojuredocs.org/clojure.core.async
I guess the best way just use XmlHttpRequest
Here some wrapper that I wrote some time ago, or just do it manually https://github.com/artemyarulin/koh/blob/master/http/transport_client.cljs#L31-L47
or wrap fetch which is also supported on RN evironments. But again in any case you need to reverse logic - do IO and in callback do render
oh well, last attempt with fetch but I still failed, will try again later 😞
(defn app-root []
[text (.-title
(-> (js/fetch "")
;; (clj->js {:method "GET"}))
(.then #(.json %))
(.then js->clj)
;; (.then success-handler)
;; (.catch rror-handler)
))])
thanks btw @artemyarulin and @beppu, learned new things today 🙂