react

"mulling over state management stuff"
Aron 2020-05-02T07:39:07.281500Z

again, I find it a bit strange that all this discussion about the React Fiber scheduler is only happening now even here. This is over 3 year old stuff. It does seem to me that people equate "last major version" -> "least risky" -> "least buggy"

Aron 2020-05-02T07:39:30.282100Z

so there is zero interest in anything else because by definition it can't be a better choice

Aron 2020-05-02T07:40:30.283300Z

and the react team helps with this by keeping stuff "experimental". Even if it's known that it's much more probable that if your code doesn't work with concurrent mode, you are using bad logic than that there is a bug in Fiber

Aron 2020-05-02T07:41:43.284200Z

the scheduler suspends render, that's why by default it is called twice, and that's why at first components sometimes get called with null props, that's state that is not ready yet.

Aron 2020-05-02T07:42:24.285Z

that is all what is required to be remembered, that the render happens on a detached loop that takes state from the rest of the system.

Aron 2020-05-02T07:43:02.285900Z

I also like the fact how they used a very minimal system with 2 fibers switching between each other, it's neat and very philosophically/physically correct way to do it

Aron 2020-05-02T07:44:03.286800Z

what I don't like is "the rest of the system", they are trying to write a database (I mean, even you talk about ACID here...) inside a UI library.

Aron 2020-05-02T07:44:05.287Z

just no.

Aron 2020-05-02T07:57:10.299400Z

also, I find the theoretical talk bothersome, and I don't want to be rude or cynical here, just want to point out that local state is wrong abstraction for UI usually, the data stored is accessed only by implemented methods. and these tie up into a transactional, or REST interface. Machine talking to machine. With user interfaces this is not true anymore. The data you query from your local states all get mixed up into a relatively small screen, overlapping, mixing, etc. Good interfaces can use data from very different parts of the state, so that they give a better narrative, a better story. Which means that your components will have to either expose their local state, effectively becoming tiny little global states that are managed from the leaves of your app, exactly where most of the development work happens, so where most of the editing is done, so where most of the mistakes are introduced. Not good. Or, what React says, you lift the state up: https://reactjs.org/docs/lifting-state-up.html As I said, I consider this documentation page an admission of failure. This literally says you should always have a shared component for all your shared data. But that's terrible if you have mostly shared data. Furthermore, the whole thing with the flux pattern or the Elm Architecture or what redux/mobx do is to have a manageable way to do this global state where you eventually end up with, at least if you do user interfaces with lots of interconnected components. Making the communication layer explicit and the state external (global) doesn't mean that all your components suddenly can overwrite any state, since a pub/sub pattern can also check for whoever wants to write whereever and you can implement any logic over that check compiletime or runtime even. Also doesn't mean that they have to see everything since it's possible to create react elements in a way that you feed them only the data they need (like om/next)

Aron 2020-05-02T07:57:54.300Z

https://gist.github.com/ashnur/f2fb2cf230d47aea9a63123aedb5926a this is how I solved last time in javascript the communication layer.

Aron 2020-05-02T07:58:21.300500Z

the comments are a bit misleading, those are more like compromises than actual problems

Aron 2020-05-02T07:59:45.301500Z

the only realy bad part is where I use window, but it was more of a demo and we didn't know how to actually handle state, and after I wrote this, react released Hooks, so it became somewhat redundant

Aron 2020-05-02T08:00:26.302600Z

Hooks are a better fit for what I do at work, where we almost never have lots of interconnected data, just big forms

orestis 2020-05-02T08:01:39.304400Z

This is intriguing, but hard to follow right now (for me). Is there a design document that could describe the high level architecture of the gist you pasted?

1๐Ÿ‘
Aron 2020-05-02T08:03:04.306900Z

I think this is too general for a design document, but maybe I misunderstand the question.

orestis 2020-05-02T08:03:10.307100Z

Right, big forms/interconnected data - the trade offs are different which is why itโ€™s hard to even have a discussion about state management. Of course in a long lived product what starts as a small form will graduate in 2 years to something g more complex.

Aron 2020-05-02T08:04:20.308200Z

the good thing about forms is that you have clear state transitions, so even in the worst case scenario, you can interrupt the user with errors and such

Aron 2020-05-02T08:04:56.309Z

In a more dynamic application it can be bad UX to start dropping error elements everywhere inside the page

orestis 2020-05-02T08:06:35.311300Z

Iโ€™m not sure I understand if youโ€™re advocating for global state or not ๐Ÿ™ƒ

Aron 2020-05-02T08:06:52.311600Z

The gist of what I am trying to say is that the scope of react applications is such that in most cases any kind of state management works, but in some cases the boundaries are so constrained that only independent sources of global state makes sense. Otherwise you have to deal with bad tradeoffs, which is what you were talking about in the past couple of days on this channel.

1๐Ÿ’ฏ
Aron 2020-05-02T08:07:18.312100Z

Not just global state, but multiple SSOs

orestis 2020-05-02T08:08:14.313100Z

An example would help! (SSO = single source of ?)

Aron 2020-05-02T08:08:24.313300Z

state ๐Ÿ™‚

Aron 2020-05-02T08:09:23.314200Z

I am working on a couple of demos, or rather, I made the repo for it and trying to setup cljs

orestis 2020-05-02T08:11:35.317500Z

I think that I agree with the multiple states idea - at least in the logical sense. A big form is probably only a part of a more complex app. There should be some documented interactions at the boundary, but the components inside the form should be concerned with the form-local state - to them it would be global though.

Aron 2020-05-02T08:13:27.319300Z

No, in our case the form is the whole app, it's served through Django. So it's not a single page app in any sense.

orestis 2020-05-02T08:16:03.324200Z

Example from how iOS/macOS does things - you instantiate a controller which encapsulates a view. You provide the controller with a few callbacks or a delegate object. You add the view to the visual hierarchy, the user interacts with the view, your callbacks get called. This in practice means a very clear boundary between state, events etc. Iโ€™m still not sure how this plays out in the web version.

Aron 2020-05-02T08:17:44.326100Z

Sure, an InputWhatever should be the controller of the state of the input value. But that's only the easy part of this problem. It's not enough to consider that only case. โ€ข it can be that InputWhatever might need to read state from another InputBhetever's value โ€ข or InputChetever might need to read the value of InputWhatever โ€ข or All of them need to read some remote state you have to fetch separately Traditional encapsulation from OOP would result in a terrible UX and a locked up user interface. (Sync mode in React) Or as they say, you would lift this state up, but suddenly, you have some inputs that don't control their own state, isn't that what you said should not happen?

orestis 2020-05-02T08:20:27.327700Z

I never said anything concrete, I usually just ask questions ๐Ÿ˜›

orestis 2020-05-02T08:21:43.329500Z

But an input field on its own is usually the wrong level of abstraction.

Aron 2020-05-02T08:22:28.331Z

for what? ๐Ÿ™‚

orestis 2020-05-02T08:22:42.331600Z

As usual in the web space , we are operating at a super low level of abstraction with limited primitives. Hence this Tower of Babel.

Aron 2020-05-02T08:23:06.332200Z

Input field is not what I was talking about. An InputWhatever could be a complex app that asks for several seperate piece of data.

Aron 2020-05-02T08:23:29.332600Z

it could be an input field, but that would usually not be enough

Aron 2020-05-02T08:26:06.334500Z

in fact, I believe that the problem is exactly the opposite web space yes but not low level primitives, I can just subscribe to keypress and keydown and similar things. Print, record video, etc. and not low level abstractions, unless you mean the communication layer where we are stuck with callbacks and promises, which I do admit are a bit too low level, I like queues

orestis 2020-05-02T08:26:09.334700Z

Would it ask for data , or should the data be provided to it? Does that data change during the lifetime of InputWhatever ? Itโ€™s hard to design things in the abstract :)

Aron 2020-05-02T08:27:48.337600Z

it's an UI Input component, so its business objective is represented by its name, which is to ask data from the USER with which it INTERFACES. It usually also has data provided to it from hardcoded and asynchronous sources, like auth and validation and generally feedback towards the USER ๐Ÿ˜‰

Aron 2020-05-02T08:28:18.338300Z

I don't write either of those like 1% of the time

Aron 2020-05-02T08:28:43.339100Z

CSS is mostly generated or written by artists

orestis 2020-05-02T08:28:47.339300Z

Yeah, but youโ€™re moving around the topic. I was asking about the whole shared state thing.

orestis 2020-05-02T08:30:16.339900Z

Yeah youโ€™re in a different space than me then :)

Aron 2020-05-02T08:36:18.340100Z

I am sorry, I don't believe I am. The original comment from https://clojurians.slack.com/archives/C012GLC2SAZ/p1588407464326100 was a response to https://clojurians.slack.com/archives/C012GLC2SAZ/p1588407095317500 specifically where you say that > the components inside the form should be concerned with the form-local state - to them it would be global though. And I tried to highlight that component's own state (or form's own state in this case) being local only solves 1/4 of the possible scenarios and just the easiest of them. in this comment where you say I move around ;) https://clojurians.slack.com/archives/C012GLC2SAZ/p1588408068337600 I still talk about the same things, but from the Component's perspective. Sure all your own state appears global, but how do you share state between different React apps on the same page? That would be an "asynchronous source".

Aron 2020-05-02T08:43:51.340800Z

I am curious now ๐Ÿ™‚ What space are you in?

orestis 2020-05-02T08:48:27.342800Z

An adjacent one that cares about CSS and visuals - and also frontend architecture ๐Ÿ˜‰

orestis 2020-05-02T08:59:20.344300Z

Gotta go - Iโ€™m enjoying this conversation even though I think we need a shared vocabulary - or I need to stop trying to figure things out on my phone on a Saturday morning :)

Aron 2020-05-02T21:16:25.344400Z

It's a bit rude to insinuate that I don't, just because I claim that it's not big part of the complexity that stems from sharing state...