Hi, I'm following along with the readme. Do I have a typo here?
https://s3.us-east-2.amazonaws.com/photoblobs/2017-08-02_012644.png
@escherize it's in :rum/args
. Oh wait. let me double check
Oh, I see. Is that a typo in the README then?
hmm, no, it's actually in state, only props is in :rum/args
I expected it to be in state. It doesn't seem to be there though.
ok I got it, you forgot to add watch on the component. If you want to change the state manually like above, you need to have add-watch
Not sure I understand. add-watch works on atoms, but I'm not using any atoms here am I? Apologies if question is odd - I'm new to rum. 🙂
for sure, I will send you a source code from rum. It explains things better.
How would you change this to actually work? I coppied this code from the readme, so once it's fixed I can make a PR to fix it
(rum/defcs time-label < { :did-mount (fn [state]
(assoc state ::time (js/Date.))) }
[state label]
[:div label ": " (::time state)])
yeah, I haven't read the part closely. However, if you check this example:
(rum/defcs component < rum/static
rum/reactive
(rum/local 0 ::count)
(rum/local "" ::text)
[state label]
(prn (keys state)))
you should see ::count
and ::text
Yep, I see them.
looks like that.. anonymous mixin isn't working as expected, ey?
then let's get back to your initial example:
this is how rum/local
works:
https://github.com/tonsky/rum/blob/gh-pages/src/rum/core.cljs#L242-L255
basically, it creates an atom and then add-watch on that atom to rerender the component. You have to do the same for your init example. basically, the ::time is there in state but the component is not re rendered so you don't see it.
@escherize did-mount
only runs AFTER your initial render. That's why you don't see the key in there. Change it to will-mount
if you want.
Ah, yes. :will-mount
fixed it.
Here's a fix for the readme then: https://github.com/tonsky/rum/pull/147
Thanks for ur help you guys. 👌:skin-tone-3: