Nested-grid is getting more stable, with virtualization built in https://re-com.day8.com.au/#/nested-grid
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.
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 ?
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.
OKAY so I added a subscription and now it.. works as expected!?!?!?!??
oh so it's a bug in re-frame 10x ?
no watchers in the app so the value it shows is always stale ?
it could be that, I suppose!
anyway thanks @rolthiolliere for your message that got me to try adding a subscription which got me over that hump.. whew!
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)
what's your version of re-frame-10x? I think we fixed a similar issue last year.
specifically caused by event-handlers with no :db effect.
maybe try adding {:db db} to all your event handlers, the issue might vanish.
but that particular problem should be fixed on the latest release
version 1.9.10
looks like I'm one release behind...
> 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.
(adding :db db made no difference... only having an actual subscription does anything)
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"]])
re-frame version: 1.4.3 http-fx version: 0.2.4 cljs-ajax version: 0.8.4