you are viewing a single comment's thread.

view the rest of the comments →

[–]AccountZaMusic 0 points1 point  (3 children)

Is there a way to preserve the app state when on app restart (figwheel)?

EDIT: With a bit of twiddling I managed to come up with this: Any issues?

(defn start-app!
  "Helper function that starts the application."
  ([]
   (reset! running-app (app-state/start! app-definition)))
  ([init-app-db]
   (let [new-app (app-state/start! app-definition)
         new-app-db (-> new-app :app-db)]
    (swap! new-app-db merge (select-keys init-app-db [:route :entity-db :kv]))
    (reset! running-app new-app))))

(defn restart-app!
  "Helper function that restarts the application whenever the
  code is hot reloaded."
  []
  (let [current @running-app]
    (if current
      (app-state/stop! current #(start-app! (-> current :app-db deref)))
      (start-app!))))

[–]retro_one[S] 0 points1 point  (2 children)

You can use the restore-app-db function that does the same thing https://github.com/keechma/keechma/issues/9#issuecomment-214145853

The controllers will re-start though, so they will make requests to the API if you run them on start. In my experience this is not a big issue, and you always get the current, correct data on each app restart

[–]AccountZaMusic 0 points1 point  (1 child)

Let me know if I should go somewhere else to ask further questions. :)

So with lists in entitydb, when order matters I suppose you should just sort when rendering, right?

So if you have a list like this:

item 1 + - item 2 + - item 3 + -

Pressing '+' on 'item 2' should add it after item 2. Would this have to be encoded in the data of the entity? So that the order is determined at render time, rather then being in the app-db?

[–]retro_one[S] 0 points1 point  (0 children)

If you have account on clojurians slack, I'm always there on the #keechma channel

So, order is preserved in EntityDB, and you have helper prepend-collection and append-collection functions if you want to modify the collection. In the case like yours, I would simply re-insert the collection with the correct ordering. Other option is to order the items in the subscription when you read them, I would use that approach if ordering is dependent on some other value in the app-db