In a ‘single page application’ that is managed by Elm, we might still have multiple routes (So the name ‘single page app’ is maybe somewhat of a misnomer), each pointing to a different page. However, on each of these pages, we might actually want to show different information.
Now, I am wondering what common patterns are to manage the change in state between these pages. I can think of some, which I will describe below, but I’d really like to know what patterns you came up with, and what their advantages and drawbacks are.
- Simple: Throw away current page data whenever switching pages. (re-)request information every time you visit a given page. Very simple to implement, but might take a long time to load pages.
- Lazy Tree: Give every page its own section of the model (For static pages, a type with multiple constructors. For dynamic pages (like when you are on a page showing a single instance of a data structure), store them in a Dict. All data, once loaded, is cached. We depend on changes to this data to be pushed to us once they happen (using e.g. Websockets) Might lead to high memory usage, but is very fast once the information is loaded.
- Cache of Recent Pages: Give every page an entry in a list (or other bounded data strucure) of a maximum size. When we change pages, the new page’s data is added to the front, and the oldes element in the list is dropped. recently-visited pages are therefore still in this cache, but we do not ever-increase memory usage.
Please tell us about your approaches!