Fork me on GitHub
#re-frame
<
2022-04-28
>
Ted Ciafardini13:04:05

Another documentation clarification question: Whenever any event is triggered, all reg-sub query functions are automatically run. Is that correct?

ribelo13:04:10

reg-sub are fired when the db changes

ribelo13:04:28

it happens in a cascade, because first those that depend directly on db, and then those that depend on those reg-sub that have recalculated

ribelo13:04:37

re-frame creates a graph of interdependent reagent atoms

Pablo14:04:49

Is there a document where docs explain that multiple rf/subscribe calls does not create multiple nodes on signal graph?

p-himik15:04:42

You mean when the arguments to different rf/subscribe calls are the same, right?

Pablo15:04:15

Sorry, to multiple rf/subscribe calls to the same subscription. For example:

(for [x (range 10)]
  [:span (<sub [:foo])])

Pablo15:04:45

I don’t remember if sometime I read that this does not create multiple reactions (low level). I’m thinking on performance.

p-himik15:04:50

Indeed, corresponding reactions are cached, so in that case only one reaction is created.

p-himik15:04:16

From the docstring of subscribe:

**De-duplication**

  Two, or more, concurrent subscriptions for the same query will
  source reactive updates from the one executing handler.

p-himik15:04:05

Although I guess the wording is quite opaque when you don't know that the cache exists. :) In any case, the implementation of the caching is also rather straightforward.

Pablo15:04:57

I remember that was explained in one of the md docs, but maybe I did read it from there. Thanks

Pablo15:04:12

It was from that document 😃

👍 1
diego.videco15:04:15

Hello. Is there a way to compose several event-fx (particularly of the :http-xhrio kind) in way similar to how promises compose in JS? I have a chain of events the should execute in order, and each event should take the output of the previous one, some of these events are http requests and I would like to have a general error handler for these requests instead of one per request. Currently I have a bunch of separate effects and each one points to the next either by calling the next in the :fx vector or on the :on-success or :on-failure keys of the :http-xhrio. However the approach seems somewhat verbose and the flow is hard to grasp for people other than the one writing the code.

p-himik15:04:32

Maybe this will help, although I haven't used it myself: https://github.com/ingesolvoll/re-chain

octahedrion16:04:08

I haven't used re-frame in a while and I can't remember how fx & cofx work. How do I express the loading of a file via js/FileReader and its subsequent callback from (.addEventListener reader "load" callback-fn) in terms of fx & cofx ?

p-himik16:04:09

If we abstract away the specifics, all that's left is the need to handle an async operation. With that being said, coeffects don't support anything async, but effects do. So what you can do is create an effect for reading files and pass something like :on-read to it which would be an event fired by that effect with the file's contents once the reading is done.

Kira McLean17:04:17

Is there a way to dispatch an event that reframe reacts to from outside re-frame? (ok if it’s super hacky, like could you put the reframe dispatch function on the window and call that from inside another framework, like Vue or React, or plain JS?) any other crazy ideas that might work for something like that?

p-himik17:04:53

Just use something like

(ns a.b
  (:require [re-frame.core :as rf]))

(defn ^:export dispatch [event]
  (rf/dispatch event))
And then in JS you'll be able to do a.b.dispatch(some_cljs_vector).

Kira McLean17:04:17

perfect.. was going down this road, this might just work :face_vomiting:

Kira McLean17:04:41

context is trying to strangle a very out of date app.. re-writing the whole thing in one go isn’t feasible, but slowly migrating one component at a time as we have to change might be.. re-frame for the new version might be an option, so curious if anyone has tried anything like this.

Prometheus20:04:28

Hey when loading initial data on a route using reitit frontend what is the idiomatic way. I know it can be done using the controllers, but it feels very weird to call dispatch inside a router. Have any of you found another way or is this is very reitit specific?

Pablo20:04:45

I think controllers is the common way to initialize some specific data of a route. There is an example on reitit repo: https://github.com/metosin/reitit/tree/master/examples/frontend-re-frame You could also initialize data on main (`init!`) using dispatch-sync (maybe also using https://github.com/day8/re-frame-async-flow-fx) but that is application data. It depends of what you need.

Prometheus04:04:23

Okay, I'm interested in lazy loading only the necessary data for each route (sub application) since the app is quite data heavy. But if it is idiomatic to use re-frames dispatch within the controllers that's probably okay. I'm only afraid that it will crash with other events, but since re-frame uses an event queue it will probably be okay(?).