State hydration #103
Labels
A-templates
Area: templates
C-enhancement
Category: enhancement
D-hard
Difficulty: hard
P-medium
Priority: medium
S-in-design
Status: in design
Milestone
Right now, Perseus is fundamentally a tool for generating some initial state in a variety of ways and then passing that to a template, which then generates a view to display to the user. But, what if state had a continued role? The MVC style of UI programming can be used with Perseus, but I think it would be cleaner and more powerful if Perseus could make state reactive, so that templates could then base their entire data requirements around their state.
This would a potentially very powerful approach, and it makes the idea of state much clearer to me personally. Of course, this is a more prescriptive development pattern than Perseus allows today, so I think this might be best achieved with a macro alternative to
perseus::template
likeperseus::mvc_template
.From there, my next inclination is to create some kind of global mutable state store for all templates, which would allow templates to retrieve their state again if the user navigates back to them. In theory, given this is all JSON-compatible, that state could even be stored in something like
IndexedDB
in the browser.Thinking of #4, which would allow many templates to operate in a single UI, a global state store would allow these to communicate with each other in a quasi-asynchronous fashion, as if synchronizing state across threads. Message passing could also be implemented for that as an alternative pattern.
This is all very interesting stuff (to me), and I think it's worth implementing as much of this as possible in the next few releases. Most will likely have to wait until Sycamore has deep state reactivity, but I think this model of hot state could be very powerful not just for apps generally, but also for development, as it would allow what is effectively HMR in Rust. The development bundle would be able to write state to
IndexedDB
and then read it back after a reload to restore a template's state. This might even be able to extend to an extra development store that holds all input values, button states, etc., which would allow HMR across rebuilds, reloads, and even browser closures if you let theIndexedDB
data persist, which is pretty crazy!This issue will be a tracking issue for the many aspects of what I've just walked through, and I hope most, if not all, of this will be ready for v0.4.0!
The text was updated successfully, but these errors were encountered: