Fork me on GitHub
#rum
<
2017-08-02
>
escherize06:08:37

Hi, I'm following along with the readme. Do I have a typo here?

jimmy06:08:30

@escherize it's in :rum/args. Oh wait. let me double check

escherize06:08:30

Oh, I see. Is that a typo in the README then?

jimmy06:08:18

hmm, no, it's actually in state, only props is in :rum/args

escherize06:08:33

I expected it to be in state. It doesn't seem to be there though.

jimmy06:08:39

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

escherize06:08:07

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. 🙂

jimmy06:08:09

for sure, I will send you a source code from rum. It explains things better.

escherize06:08:18

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)])

jimmy06:08:43

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)))

jimmy06:08:54

you should see ::count and ::text

escherize06:08:03

Yep, I see them.

escherize06:08:30

looks like that.. anonymous mixin isn't working as expected, ey?

jimmy06:08:38

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

jimmy06:08:26

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.

rauh06:08:08

@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.

escherize06:08:37

Ah, yes. :will-mount fixed it.

escherize07:08:45

Thanks for ur help you guys. 👌:skin-tone-3: