This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-30
Channels
- # 100-days-of-code (2)
- # announcements (2)
- # beginners (8)
- # boot (6)
- # calva (52)
- # cider (6)
- # cljs-dev (11)
- # cljsrn (3)
- # clojure (58)
- # clojure-austin (2)
- # clojure-russia (6)
- # clojure-spec (23)
- # clojure-uk (12)
- # clojurescript (29)
- # datomic (10)
- # emacs (1)
- # figwheel (2)
- # figwheel-main (2)
- # fulcro (3)
- # luminus (1)
- # off-topic (38)
- # re-frame (21)
- # ring-swagger (1)
- # robots (1)
- # shadow-cljs (65)
- # spacemacs (3)
- # tools-deps (16)
hi, what is the correct way of fetching initial data during load? i am using re-frame and sente and i want to fetch dropdown items during init but it doesnt happen re-frame dispatch happens before sente initialization and i am not sure where and how to 'delay' dispatch so it happens after sente init
(defn- send-event-when-open [chsk-send! chsk-state event]
(if (:open? @chsk-state)
(do
(timbre/info "Sending event on an already open connection: "
event)
(chsk-send! event))
(do
(timbre/info "Connection closed, waiting until open: "
event)
(add-watch chsk-state :subscribe
#(when (:open? %4)
(timbre/debug "Connection open sending event: "
event)
(chsk-send! event)
(remove-watch chsk-state :subscribe))))))
I've added a workaround so my events are sent only when connection is open👍 4
(defn start-ws []
(start-websocket)
(sente/start-client-chsk-router! ch-chsk event-msg-handler)
(js/setTimeout #(rf/dispatch [:all-items]) 500)
)
any suggestions to make it better?@lepistane So the :all-items
handler fetches data using a websocket?
(reg-event-db
:all-items
(fn-traced [db [_]]
(ws/chsk-send! [:all-items]
3000
(fn [reply]
(if (sente/cb-success? reply)
(dispatch [:show])
(js/alert "No reply"))))
db))
i know effect should be used but i am making it as simple as i can and slowly making it right
Do you know for sure after the (sente/start-client-chsk-router! ch-chsk event-msg-handler)
if the websocket is inited correctly? If so you shouldn't need the timeout