re-frame

https://github.com/Day8/re-frame/blob/master/docs/README.md https://github.com/Day8/re-frame/blob/master/docs/External-Resources.md
az 2021-02-19T02:25:42.162200Z

Thanks @andrea_fleckenstein @p-himik, still trying to work through it. Basically I am just trying to figure out how to denormalize the store and I have relationships that are arbitrarily deep. Burrito -> Sauce -> Spice blend -> Salt & Pepper I’ve been playing around with sub-raw to see if I can work through it. So far no luck. Will keep working through and come back once I have more progress.

az 2021-02-19T05:43:42.164Z

Is it bad practice to subscribe from inside a computation function in reg-sub? I’m trying to figure out how to materialize relationships but I don’t have the nested data until the computation function.

lsenjov 2021-02-19T06:08:43.164600Z

You probably want reg-sub-raw then

2021-02-19T10:03:36.166800Z

new blog post on re-frame and firebase: https://widdindustries.com/clojurescript-firebase-simple/ which talks about signal functions and limited use of re-frame app-db. feedback welcome 🙂

andre 2021-02-19T10:16:24.168200Z

hi, in some cases i can see in traces that subscription run in each tick, even if there are no changes in app-db, why it might happen ? so it seems like subscription is broken and it just run on each tick

andre 2021-02-19T10:19:28.168900Z

hm interesting if i hot reload and clear cache it won't be run anymore

andre 2021-02-19T10:57:29.169300Z

ok it seems like subscription is used in event handler

andre 2021-02-19T10:57:49.169700Z

and at some point its broken and started to run on each tick

p-himik 2021-02-19T10:58:58.170Z

It's not broken, it's just not cached.

andre 2021-02-19T11:32:59.170300Z

but why is it run on each tick ?

p-himik 2021-02-19T11:36:23.171200Z

I don't know what your code is exactly so I cannot answer that. Perhaps that event handler is called on each tick, perhaps something else.

p-himik 2021-02-19T11:37:17.171800Z

Alternatively, you might be right and there might be some bug. But again, I can't say anything without having an MRE.

andre 2021-02-19T11:46:58.172100Z

yes sure, thanks

lassemaatta 2021-02-19T11:49:55.172200Z

I also often need a snack before debugging a problem 😀

p-himik 2021-02-19T11:58:23.172400Z

I already had breakfast. :)

p-himik 2021-02-19T11:58:56.172600Z

Huh, it's been quite some time since I heard "MRE" used in a meal-related context.

Clément Ronzon 2021-02-19T16:39:46.181Z

Hey Guys! Happy Fried-day! I was facing an conflict issue in my project and I'd like to have your input on the way I resolved it. # The problem In my project I had the tim-v interceptor registered globally:

(re-frame/reg-global-interceptor trim-v)
This is handy because it makes the event handlers registration less verbose. For instance:
(rf/reg-event-fx
 (fn [_ [prop]]
   {:dispatch {::some-event prop}}))
This was working perfectly until I had to use the cool re-pressed library. This library registers event handlers the way one would if trim-v wouldn't intercept the event. For instance:
(rf/reg-event-fx
 (fn [_ [_ event-type]]
   {::keyboard-event {:event-type event-type}}))
That's where the conflict happens, because of trim-v the event-type is actually passed as the first element in the second parameter of that handler and is consequently ignored. # My solution to that problem I wrote a custom reg-global-interceptor that checks if the namespace of the event is within a whitelist, in which case it will apply the interceptor, otherwise it won't.
(defonce ns-whitelist #{"foo" "bar"})

(defn- event-is-whitelisted
  "Returns true if the event is in the namespace white list"
  [whitelist context]
  (contains? whitelist (-> context
                           (get-coeffect :original-event)
                           first
                           namespace
                           (split #"[\./]")
                           first)))

(defn- get-whitelisted-int
  "Executes the interceptor only if the scope falls in the whitelist"
  [whitelist interceptor]
  (let [{:keys [id before after]} interceptor
        whitelisted (partial event-is-whitelisted whitelist)]
    (->interceptor
      :id id
      :before #(if (and (some? before) (whitelisted %)) (before %) %)
      :after #(if (and (some? after) (whitelisted %)) (after %) %))))

(defn- reg-global-interceptor
  "Delimits the scope of the interceptor"
  [interceptor]
  (re-frame/reg-global-interceptor (get-whitelisted-int ns-whitelist interceptor)))
# Some thoughts This adds a good amount of additional computing and I am not sure how to solve that problem in a more efficient way. Thanks in advance for your help please answer in a thread

p-himik 2021-02-19T16:51:37.181300Z

In this code block:

(rf/reg-event-fx
 (fn [_ [_ event-type]]
   {::keyboard-event {:event-type event-type}}))
why not replace [_ event-type] with just [event-type]?

Clément Ronzon 2021-02-19T17:01:07.181500Z

Because this code is from re-pressed which is an external project/dependency: https://github.com/gadfly361/re-pressed

p-himik 2021-02-19T17:03:15.181800Z

I see. In general, I don't think that it's a good idea to use event-modifying interceptors globally. In my projects, I have a custom versions of reg-event-* functions that inject that interceptor automatically. kee-frame does it as well, for example.

Clément Ronzon 2021-02-19T17:05:09.182Z

Good point! This means that my problem is due to a bad pattern/design. Maybe it'd be good to mention exactly what you just wrote in re-frame's documentation about interceptors? :)

p-himik 2021-02-19T17:07:39.182200Z

Perhaps - you can always open an issue an submit a PR. :)

Clément Ronzon 2021-02-19T17:08:48.182400Z

But I would steal those lovely words from you 😄 I'll try, thank you @p-himik!!

p-himik 2021-02-19T17:10:26.182600Z

I consider all my community activities to be under the CC license. :) NP!

1👍