Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devcards support hot code reload loses state #75

Open
awkay opened this issue Apr 16, 2017 · 1 comment
Open

Devcards support hot code reload loses state #75

awkay opened this issue Apr 16, 2017 · 1 comment

Comments

@awkay
Copy link
Contributor

awkay commented Apr 16, 2017

Need to change the macro to do something more like in the om next helpers:

bhauman/devcards@234a91d

@awkay
Copy link
Contributor Author

awkay commented Apr 17, 2017

This is a relatively easy fix. The following code will work as long as the cards don't share the same root UI node:

(defmacro untangled-app
  "Embed an untangled client application in a devcard. The `args` can be any args you'd
  normally pass to `new-untangled-client` except for `:initial-state` (which is taken from
  InitialAppState or the card's data in that preferred order)"
  [root-ui & args]
  (let [s (symbol (str (name root-ui) "-application"))]
    `(devcards.core/dom-node
       (fn [state-atom# node#]
         (defonce ~s (atom (untangled.client.core/new-untangled-client :initial-state state-atom# ~@args)))
         (reset! ~s (untangled.client.core/mount (deref ~s) ~root-ui node#))
         ; ensures shows app state immediately if you're using inspect data and InitialAppState:
         (js/setTimeout (fn [] (swap! state-atom# assoc :ui/react-key (untangled.client.util/unique-key))) 1000)))))

If we wrap that in a defuntangled-card macro we can leverage the unique symbol there to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant