This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-13
Channels
- # announcements (4)
- # babashka (1)
- # beginners (124)
- # calva (5)
- # cider (3)
- # clara (3)
- # clerk (5)
- # clj-commons (14)
- # cljdoc (12)
- # cljs-dev (14)
- # clojure (43)
- # clojure-austin (23)
- # clojure-europe (55)
- # clojure-nl (1)
- # clojure-norway (11)
- # clojure-uk (2)
- # clojurescript (34)
- # conjure (1)
- # cursive (1)
- # data-science (28)
- # datomic (3)
- # fulcro (20)
- # gratitude (2)
- # hyperfiddle (6)
- # introduce-yourself (1)
- # jobs (5)
- # lsp (56)
- # malli (5)
- # membrane (7)
- # mount (5)
- # off-topic (16)
- # polylith (39)
- # portal (38)
- # practicalli (1)
- # rdf (1)
- # re-frame (8)
- # releases (8)
- # remote-jobs (4)
- # shadow-cljs (49)
- # sql (1)
- # xtdb (36)
Hi, I can't find something about the issue that I have with re-frame on the web. So I try my luck here. I try to add a webworker to my re-frame application, but I do get some error from re-frame-10x.events. It tries to call a function on window, which does not exist in the webworker.
(rf/reg-event-fx
:global/add-unload-hook
(fn [_ _]
(js/window.addEventListener "beforeunload" #(rf/dispatch-sync [:global/unloading? true]))
nil))
Does someone have an idea to prevent this error?First of all, side effects should be performed in effect handlers, not event handlers. Second of all, it has nothing to do with re-frame itself. You're just using functionality in web workers that's not intended to work with web workers. In this case, it's via re-frame-10. As far as I know, re-frame-10x isn't intended to be used with web workers at all, so all you need to do is to not use it there. :) I'm gonna guess that it's due to preloads, and when you compile the web worker code you can simply remove the re-frame-10x preload.
I’m having a momentary struggle with structuring an event handler.. I’m upgrading an existing handler that can take 1 item to one that takes a vector of items, and I’m not sure where to do the iteration. The handler in question, halfway between supporting multiple values:
;; e.g. (rf/dispatch [::persist-entities {:people :person-id [{:person-id 1 :name "Bob"} {:person-id 2 :name "Tim"}]
(reg-event-fx ::persist-entities
(fn-traced [{:keys [db]} [_ {:keys [entity-type-keyword entity-id-key value]}]]
(let [id (:entity-id-key value)]
{:db (assoc-in db [:app :entities entity-name id] value)})))
Is it a good bet to build 1 map that has the items key’d to their ids, then do one
update-in data [:app :entities entity-name] assoc id-keyed-map```
Or like.. a loop or for in the let to assoc-in a bunch of times? First options seems cleaner but wasn’t sure i there were hidden traps that way.Seems like not re-frame related at all and just a generic data handling question. If so, then by itself it doesn't matter at all, as long as your data processing gets you the right data and that data shape is suitable for your needs.
If you can get away with just assoc'ing a single map - sure, do that.
If you need to do more than that, I'd use reduce
.