This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-17
Channels
- # announcements (13)
- # beginners (56)
- # brompton (1)
- # cider (2)
- # cljsrn (10)
- # clojure (369)
- # clojure-australia (4)
- # clojure-boston (1)
- # clojure-europe (28)
- # clojure-nl (1)
- # clojure-spec (1)
- # clojure-uk (18)
- # clojurescript (26)
- # data-science (2)
- # datahike (4)
- # datalog (2)
- # datasplash (6)
- # datomic (9)
- # events (1)
- # kaocha (4)
- # macro (1)
- # malli (22)
- # meander (40)
- # membrane (30)
- # music (1)
- # nbb (3)
- # news-and-articles (3)
- # off-topic (12)
- # practicalli (1)
- # re-frame (19)
- # remote-jobs (1)
- # sci (22)
- # shadow-cljs (15)
- # spacemacs (4)
- # tools-deps (40)
- # xtdb (26)
Hey all. I have maybe a silly question. I am trying to make use of local storage. I am able to set a key/val and I would like to access it via coeffects:
(rf/reg-cofx
::get
(fn [cofx k]
(assoc-in cofx [:local-storage k] (get-item k))))
I cannot seem to find the :local-storage
key inside of my coeffects map when inspecting events from reg-event-db
. Do I have to include this somewhere? Currently it is just registered and not included anywhereYes, otherwise reg-cofx
is never called and re-frame doesn't know about it. You should've received a warning in the JS console mentioning it.
I guess I'm not sure how to include it. I saw there is a way to inject into co-fx, however that seems to be different to what I want t odo
Oh? So the namespace is included in the larger events ns. I guess I'm wondering how to get that data I saved in local storage out? A subscription?
Ah, if it's already included then that ::get
should be available. Just make sure that you're using the right namespace, because ::get
in one ns is different from ::get
in another one.
If you need the data in an event, then a cofx is a right tool - not a sub. Especially since subs wouldn't know about LocalStorage changes, unless you decided to duplicate all the data in your app-db or do something very clever with reg-sub-raw
.
Ah, well damn. It seems like maybe a cofx is not what I want. But for my knowledge. I am still not seeing it inside of the cofx map: Do I have to do something like this:
(rf/reg-event-fx
::dothething
(fn [cofx _]
{::localstorage/set! [:meow "hithere"]
::localstorage/get :meow}))
No idea, there's too little information for me to give you a useful answer. Have you tried looking at the implementation of the things that already exist out there? Like https://github.com/akiroz/re-frame-storage and https://github.com/deg/re-frame-storage-fx for example.
Is there a reason why you wouldn't suggest using a cofx to modify the app db upon initialization of the page?
Sure thing. But I'm still not sure what exactly we're talking about. Why would you want to use a cofx and not the event handler itself to modify app-db?