Fork me on GitHub
Ted Ciafardini13:04:05

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


reg-sub are fired when the db changes


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


re-frame creates a graph of interdependent reagent atoms


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


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


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

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


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


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


From the docstring of subscribe:


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


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.


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


It was from that document 😃

👍 1

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.


Maybe this will help, although I haven't used it myself:


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 ?


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?


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.


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?


I think controllers is the common way to initialize some specific data of a route. There is an example on reitit repo: You could also initialize data on main (`init!`) using dispatch-sync (maybe also using but that is application data. It depends of what you need.


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(?).