Fork me on GitHub
#rum
<
2018-01-28
>
sparkofreason00:01:09

I'm missing something fundamental about how rum (or React) works. Calling (rum/mount (app session) (js/document.getElementById "app")) sets the session on the first call, but does not update it subsequently, even though session has changed. Is that expected? And if so, what is the correct way to update props (apart from fiddling around with atoms)?

justinlee01:01:14

@dave.dixon I think at the top level you must use an atom. Without it, why would you even expect the app component to update? After all, the props haven’t changed. You should expect the same thing in javascript.

sparkofreason01:01:15

The props have changed. That change just isn't being propagated by mount. Which I understand given the code, but am wondering if there is a way to accomplish without an atom.

justinlee01:01:07

The “props” are what you pass. If you pass the “session” and then later change it, it isn’t going to update because you haven’t passed new data. Just like in javascript if your top level mount was <App session={session}/> or something, it wouldn’t update if the session changes later. I think the rum code you’ve written is effectively the same as that.

sparkofreason01:01:03

It wouldn't change if I called mount again with the new vallue of session?

justinlee01:01:53

yes it would

justinlee01:01:13

well I think it would, i’ve never done a remount

justinlee01:01:33

there’s a section in the readme that says remount should work https://github.com/tonsky/rum#updating-components-manually

sparkofreason01:01:38

Right, that's what I thought too. I have my own mixin here, but it's pretty simple, but maybe I did something really brain-dead and managed to always return the initial session.

sparkofreason01:01:45

Maybe it is my mixin. I tried removing it above, and appear to get correct results.

sparkofreason01:01:04

Crap. I think I just wrote the :did-remount function wrong. I knew I was missing something stupid.

justinlee01:01:43

@dave.dixon any particular reason why you are avoiding atoms? seems like that’s what they are made for

sparkofreason02:01:47

In this case, the atom would just be a level of indirection that doesn't add much, because session isn't map, but something where I have to do a more complex calculation to pull out the data needed by sub-components. And I want to be able to author components independent of any specific global atom, so they can be re-used in different apps etc. So either I'm pushing in the atom on first render, or pushing in the value on re-render, which in the end seems like a wash at best.

sparkofreason02:01:13

Anyway, it turns out my problem was :did-remount, working great now. Thanks for helping work through my brain-fart there.

justinlee02:01:42

cool glad it worked out