re-frame

Kimo 2025-06-10T23:30:48.695669Z

Nested-grid is getting more stable, with virtualization built in https://re-com.day8.com.au/#/nested-grid

❤️ 2
Patrix 2025-06-10T02:39:10.918119Z

I'm having a strange issue with the :http-xhrio effect and its :on-success handler (which is a db event). High-level: I have an event (that I trigger via e.g. clicking a button), which fetches some data from the backend, and the event-db which is triggered on success, which adds the data to the app db. HOWEVER: the first time I click the button, almost nothing happens. So in re-frame-10x I see the first event is triggered, and in the browser console I do see the output of some js/console.log function I have in the event-db, but the db doesn't get updated! Then if I click the button again, the first db update happens, the 2nd http-xhrio event happens, but again the event-db does not happen until I click the button again. Seems like there's always this kind of situation where the update of the app db is one step behind... Code snippets in reply.

rolt 2025-06-10T11:56:57.801339Z

The re-frame.core/debug middleware could help here. The problem you're facing is really strange, it should behave correctly. My guess would be that the value you're seeing (with subscribe ?) is not the up to date version. How are you inspecting the database state ?

Patrix 2025-06-10T12:02:34.195469Z

Hmm I'll look into reframe.core/debug re: inspecting the database: first, there's no subscription anywhere yet... for inspecting the database, I'm using println or js/console.log to print the results (in the event-db) sent on success (results are accurate), and using re-frame-10x to follow the events and inspect the app-db.

Patrix 2025-06-10T12:05:17.084509Z

OKAY so I added a subscription and now it.. works as expected!?!?!?!??

rolt 2025-06-10T12:47:13.959339Z

oh so it's a bug in re-frame 10x ?

rolt 2025-06-10T12:48:03.964329Z

no watchers in the app so the value it shows is always stale ?

Patrix 2025-06-10T12:58:07.924189Z

it could be that, I suppose!

Patrix 2025-06-10T13:28:26.662679Z

anyway thanks @rolthiolliere for your message that got me to try adding a subscription which got me over that hump.. whew!

Patrix 2025-06-10T13:29:13.287439Z

maybe I should create an issue or check the issues in re-frame-10x (I was checking for issues in every other dependency and found nothing related, never dawned on me it could be re-frame-10x)

Kimo 2025-06-10T15:09:34.353079Z

what's your version of re-frame-10x? I think we fixed a similar issue last year.

Kimo 2025-06-10T15:10:32.617469Z

specifically caused by event-handlers with no :db effect.

Kimo 2025-06-10T15:11:06.813079Z

maybe try adding {:db db} to all your event handlers, the issue might vanish.

Kimo 2025-06-10T15:11:29.740809Z

but that particular problem should be fixed on the latest release

Patrix 2025-06-11T00:38:14.706079Z

version 1.9.10

Patrix 2025-06-11T00:38:33.044319Z

looks like I'm one release behind...

Patrix 2025-06-11T00:39:20.764519Z

> maybe try adding {:db db} to all your event handlers, the issue might vanish. thing is this was happening whether I had a :db key or not in the event-fx.. My db effect was to associate some data to it rather than leaving it intact though.

Patrix 2025-06-11T00:44:29.691849Z

(adding :db db made no difference... only having an actual subscription does anything)

Patrix 2025-06-10T02:39:16.426609Z

Moreover, if I uncomment that :db effect in :tasks/get-task-list, that seems to override any update of the app db via :tasks/list-fetched. I introduced an artificial delay in the backend /api/task-list and the :db effect in :tasks/get-task-list seems to apply only after the API call completes.. From the docs I was led to understand that the :db effects should happen first.

(rf/reg-event-fx
 :tasks/get-task-list
 (fn [{:keys [db]} _]
   {:http-xhrio {:method          :get
                 :uri             "/api/task-list"
                 :format          (ajax/json-request-format)
                 :response-format (ajax/json-response-format {:keywords? true})
                 :on-success      [:tasks/list-fetched]
                 :on-failure      [:tasks/failed]}
    #_#_:db (assoc db :loading? true :tasks nil)}))

(rf/reg-event-db
 :tasks/list-fetched
 (fn [db [_ {tasks :tasks}]]
   (js/console.log tasks)
   (assoc db :tasks tasks :loading? false)))

(rf/reg-event-fx
 :tasks/failed
 (fn [_ [_ error]]
   (pp/pprint error)))

;; ...

(defn load-btn []
  [:div [:button {:on-click #(rf/dispatch [:tasks/get-task-list])} "Load tasks"]])

Patrix 2025-06-10T02:40:07.685059Z

re-frame version: 1.4.3 http-fx version: 0.2.4 cljs-ajax version: 0.8.4