-
-
Notifications
You must be signed in to change notification settings - Fork 842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Frontend Needs Proper State Management #2144
Comments
Part 1In a sequence of PRs, I'm going to convert: app.current away from components. That is, the values stored in app.* will all be states and methods relating to changing states, not component instances. Those changes can be reviewed individually, and will make the frontend rewrite easier actually, as the mechanism for changing state should still work with Mithril v2. Considering that the rewrite would depend on this, I will make this a top priority, and try to get the PRs out within the next 2 days. Considering a general lack of inderdependence, I'm hoping that each of these can be its own PR, which should make reviewing easier. Just to clarify again why this is necessary: aside from promoting good practice, we're either going to need to go this route, or use hacky workarounds in the rewrite which will come back to bite us later. |
I'm a bit confused by the term "state", because each case here is very different. Could we talk about the approach for each in detail without starting the changes? Maybe a separate issue for each one could make sense? In my opinion:
For modals and alerts, what I've used in my own v1/v2 Mithril-based applications is a manager that takes the class and props. That way there's no need to call I wouldn't call the modal and alert managers "states". I think the name "manager" is perfectly fine, it just stores information on the component currently rendered and crafts the vnodes. It just shouldn't be a component itself. |
For If you take at the current rewrite Modal Manager, is that basically what you are suggesting for it? |
Agree with everything you said about modals and alerts. However, we do still need to mount HTML/JSX probably (the stuff in the view() methods of each), so not sure where those should go? @datitisev also had the idea of assigning an ID to the 'alert state' props stored in AlertManager, so that whatever component requested it could store that ID and de-activate an alert externally, which I think is a great idea.
This one is done (and largely agreed upon except for one minor issue caused by the change) in the relevant PR, #2150 |
I suggest replacing
with something like
EDIT: or alternatively, create a new component |
I would probably prefer splitting it up into 2 classes, but I'm fine with the first approach too, as long as ModalManager doesn't need to inherit off of Component (not sure if that would cause any redraw issues?) |
@clarkwinkelmann That won't trigger lifecycle hooks though...? |
No, it wouldn't. That's the approach I used on my private Mithril projects. I have the ModalManager/AlertManager return vnodes. Then I inject those vnodes either via the global There's no lifecycle events required, all we need is for the modal manager to return |
I'm not sure I like stuff that isn't a component returning JSX. I'd say we should either put the JSX directly into the mount call, or split ModalManager (and AlertManager) into 2 classes each. As long as we later reorganize the classes so that we don't have 60 files in one directory any more, I'd say we should be fine. |
A general thought: Do we really want to trigger redraws from the states? Or do we rather want a system where states serve as "observables" of sorts that signal to anyone interested (our app, probably) when changes happen and then that place tells Mithril to redraw? |
This is a difficult question, but I'm leaning towards yes on this one. My strictest no-no would be including any jsx in state methods (not the biggest fan of storing JSX in states as in #2163, but that's not AS critical). The way I see it, every state method is either involved in:
One other thing I'll note is that I view states as an intermediate step on the way to a proper state management methodology, at which point the data in states, the public API of manipulating state would be further split off, and the reducers / observers handle animations and redraws and the like. But right now, our priority is Mithril v2.0, and we need to de-componentize everything regardless. This wave of PRs is only step 1 of the 3 step plan I outlined above. And since there's now a clear defined public API, when we make the changes in step (2), we can "symlink" the State classes API to the new system we design for BC. That's also why I want to avoid people extending / inheriting from states for now: because they're temporary. |
Okay, they're temporary, but we can still strive for more consistency then (when it comes to who triggers the redraws). I'll comment inline where I hope for more of that. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We do this to keep the amount of open issues to a manageable minimum. |
This is a lot better now that we don't store component instances, but let's keep this open for now. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We do this to keep the amount of open issues to a manageable minimum. |
We are closing this issue as it seems to have grown stale. If you still encounter this problem with the latest version, feel free to re-open it. |
1 similar comment
We are closing this issue as it seems to have grown stale. If you still encounter this problem with the latest version, feel free to re-open it. |
Architecture
Is your feature request related to a problem? Please describe.
Right now, our frontend uses somewhat of a haphazard state management / propogation system. We have:
This means that the displayed UI can be modified by:
Describe the solution you'd like
This should probably be done gradually, one step at a time. Radical change is probably not needed, however, the following steps should be individually taken:
In my opinion, (1) should be included in #1821. (2) should be aimed for before stable. (3) can be done after stable
Benefits
If done properly, this should:
The text was updated successfully, but these errors were encountered: