This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-21
Channels
- # arachne (21)
- # beginners (22)
- # boot (58)
- # cider (27)
- # cljs-dev (67)
- # cljsjs (10)
- # cljsrn (13)
- # clojure (91)
- # clojure-greece (6)
- # clojure-russia (1)
- # clojure-uk (6)
- # clojurescript (6)
- # core-async (3)
- # cursive (6)
- # datomic (3)
- # events (2)
- # hoplon (152)
- # off-topic (44)
- # om (8)
- # om-next (7)
- # onyx (16)
- # protorepl (10)
- # re-frame (10)
- # reagent (22)
- # untangled (5)
oh, thanks @edwthomas, I was about to ask about the proper way 😄
I probably should have used jquery for this, seems this is too much for cljs on its own
@edwthomas thanks for the example, but it felt short because I don't use re-frame as of the moment, only reagent, probably re-frame handles promises automatically, I think this http is eating to much of my time, not a friendly stuff to work with re-natal
@ejelome the re-frame dispatch function is just a way to update the app state that’s stored in a reagent atom. It doesn’t have any knowledge of Javascript Promises that are used by the Fetch API.
The json() method of the Response returns a Promise that you can handle using it’s then() method. That’s basically what I’m doing with the (.json response)
function followed by the (.then (fn[]….)
call.
edwthomas:
(.log js/console
(-> (js/fetch "")
(.then (fn [response]
(.json response)))
(.then (fn [post]
(js->clj post :keywordize-keys true)))
))
I'm stuck with the Promise
object: > Promise {_45: 0, _81: 0, _65: null, _54: null}
you can try your example and will see it will keep on returning a Promise
object:
(.log js/console
(->
(js/fetch "" (clj->js {:method "GET"}))
(.then (fn [response]
(-> (.json response)
(.then (fn [post]
(js->clj post :keywordize-keys true))))))))
hmm sorry I’m heading out now but will try this sometime tomorrow. I basically copied this from a working app so it should have worked. I’ll try to check it out tomorrow.
no worries, you have given too many hints, I'll try to understand it better this time, thanks a bunch 🙂