Fork me on GitHub
#re-frame
<
2021-09-30
>
Simon06:09:58

Is it possible to avoid re-initializing the database on every save while in development mode?

(defn ^:dev/after-load render
  "Render the toplevel component for this app."
  []
  (rf/dispatch [:initialize-db])
  (rdom/render [app] (.getElementById js/document "app")))

(defn ^:export main
  "Run application startup logic."
  []
  (init-analytics!)
  (render))

p-himik06:09:49

Don't dispatch :initialize-db on reload?

☝️ 1
Simon07:09:40

(defn ^:dev/after-load render
  "Render the toplevel component for this app."
  []
  (rdom/render [app] (.getElementById js/document "app")))

(defn ^:export main
  "Run application startup logic."
  []
  (init-analytics!)
  (rf/dispatch [:initialize-db])
  (render))
That partially solves it, but still internal component reagent atoms get reset on reload. Is that avoidable or just an inherent result of the re-render?

p-himik07:09:53

> internal component reagent atoms get reset on reload If you consider something a part of your app's state, use re-frame's app-db for that - don't use Reagent ratoms.

p-himik07:09:11

It's the result of re-render, it's the result of code re-evaluation upon code reloading.

p-himik07:09:41

The only solution is to move such data outside of a component and define it with defonce - which is exactly what re-frame does with its app-db.

Simon08:09:11

That makes a lot of sense. Thank you once again @U2FRKM4TW for such great and fast answers !

👍 1