rum

Simple, decomplected, isomorphic HTML UI library for Clojure and ClojureScript | 0.12.8 https://github.com/tonsky/rum/blob/gh-pages/CHANGELOG.md#0128
sparkofreason 2018-01-28T00:51:09.000097Z

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

justinlee 2018-01-28T01:42:14.000063Z

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

sparkofreason 2018-01-28T01:45:15.000033Z

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.

justinlee 2018-01-28T01:48:07.000052Z

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.

sparkofreason 2018-01-28T01:49:03.000080Z

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

justinlee 2018-01-28T01:49:53.000058Z

yes it would

justinlee 2018-01-28T01:50:13.000087Z

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

sparkofreason 2018-01-28T01:53:02.000057Z

FWIW, here's a code snipped. Elsewhere there is a loop which calls run with the new value of session whenever it changes. As written above, the component lifecycle methods are called, but always with the initial value of session. If I uncomment the call to unmount it works as desired.

justinlee 2018-01-28T01:53:33.000010Z

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

sparkofreason 2018-01-28T01:54:38.000035Z

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.

sparkofreason 2018-01-28T01:57:45.000100Z

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

sparkofreason 2018-01-28T01:59:04.000011Z

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

justinlee 2018-01-28T01:59:43.000076Z

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

sparkofreason 2018-01-28T02:03:47.000014Z

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.

sparkofreason 2018-01-28T02:04:13.000066Z

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

justinlee 2018-01-28T02:04:42.000035Z

cool glad it worked out