This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-12-02
Channels
- # adventofcode (286)
- # aws (3)
- # beginners (243)
- # calva (4)
- # cider (51)
- # cljs-dev (8)
- # clojure (74)
- # clojure-conj (1)
- # clojure-france (1)
- # clojure-italy (1)
- # clojure-spec (21)
- # clojure-uk (22)
- # clojurescript (25)
- # clojurex (6)
- # code-reviews (5)
- # core-async (3)
- # cursive (1)
- # defnpodcast (1)
- # fulcro (29)
- # mount (1)
- # off-topic (85)
- # onyx (5)
- # other-languages (7)
- # pathom (6)
- # pedestal (6)
- # re-frame (20)
- # reagent (2)
- # reitit (8)
- # ring-swagger (10)
- # shadow-cljs (53)
- # spacemacs (8)
- # tools-deps (34)
can anyone point me to example code that starts some kind of bidirectional channel? i am working on a chrome extension where the UI will use re-frame; it connects to the "backend" of the extension via a channel in the chrome API. the frontend and backend asynchronously message each other with the channel. i want to receive messages on the re-frame side of this channel and dispatch events with their data, and also handle some events by sending messages to the backend. but i am not sure when/how to create and store the actual "socket" that you send messages over.
maybe i should just connect and store the channel in a top-level atom totally outside of re-frame but that feels kind of lame 🙂
I haven't done this before but I would guess that you could add a subscription to the socket that would dispatch a message to re-frame.
Likewise, register an effect that sends a message to the socket that re-frame event-handlers can use
https://github.com/Day8/re-frame/blob/master/docs/SubscriptionInfographic.md makes it sound like subscriptions are only for moving data from app-db into view functions
Sorry, not a re-frame subscription. However you would "subscribe" to messages on the "socket"
ah okay 🙂. the question is can i run that subscription from within re-frame? i.e. on initialization can i dispatch an :init event that, among other things, returns an effect that starts this subscription? can you have effect handlers that do not ever return?
Hmm I would just do it out of band, unless there was some sort of timing component to the subscription
(under the hood this thing is a core.async channel, so it's doing that kind of subscription with a go-loop)