bhauman / devcards

Devcards aims to provide a visual REPL experience for ClojureScript
1.53k stars 113 forks source link

Does devcards reload when data changes? #15

Closed uday-rayala closed 10 years ago

uday-rayala commented 10 years ago

I see that om-root-card does not reload the card when data is changed.

For example, if I change text to "yep it is not", it does not automatically reload unless the page is reloaded

(defcard omcard-ex (dc/om-root-card widget {:text "yep it is"} {} { :unmount-on-reload true }))

Is there any option I can pass to do this?

bhauman commented 10 years ago

In order for the Devcards to be "stateful" while allowing code chages, it has to allow you to set an initial state while not blowing away the state that has accumulated so far. And that is what you are setting in the second parameter, the initial state. So it follows that when you want to return to the initial state, that you reload the page. Does that make sense?

If you want to reset to an original state without reloading the page you need to do that explicitly. IE a "reset" link in your app or you can do this:

(def state-atom (atom {:text "yep it is"}))
(dc/om-root-card widget state-atom))

;; just uncomment this line (and save file) when you want to reset the state
#_(reset! state-atom {:test "this is a new initial state"})  

It is my current opinion that reloading the page is the most natural way to "start over".

Does that help?

Also you don't want to have the :unmount-on-reload option set to true for React.

uday-rayala commented 10 years ago

Thanks for the clarification.

I understand your point about not resetting the state on unmount. But for my use case, I wouldnt mind if the state is reset on unmount. Actually, I expect that to happen always.

So may be I will try and write a new devcard to reload the state every time. I am hoping it is not very hard to write one.