I have noticed one problem that is shadowing all these thoughts:
a) Do we have a need to create type system that encodes a difference between Local and “Source of Truth” data, or the way we define complex UI elements, that often have their own states, hence we need to define some kind of structure for them, which is forcing us to encode that difference on per-problem basis.
b) Is the need to make a distinction between a Model and ViewModel, (in Firebase example Domain.Model and UIState) some kind of faulty thinking, because, then you need to manage to TWO states, ui details and data details.
I have a sense that b) is breaking TEA in some sense. I have just deployed one small solution to similar problem:
Lets say we want a small form from which you can create new DateMarkers (send it to server), edit them (by changing the date via datepicker):
type alias DateMarker =
{ date : Date
, id : Uuid
}
type alias MarkerForm =
{ markers : List DateMarker
, editing : EditState
, datepicker : DatePicker
, seed : Random.Seed
}
type EditState
= NotEditing
| NewMarker EditableMarker
| Marker Uuid EditableMarker
type alias EditableMarker =
{ date: Maybe Date
}
Ok, main point is, that EditableMarker
which is basically model for actual form that we use in view, doesn’t care about peculiarities of DateMarker
(except that shares part of the name, which is maybe ill practice). EditableMarker
describes the data in the form, if the user cancels change, I just update the state to NotEditing
, and that way you get “discard change” for free, because only on Save
is where you apply the change depending what the EditState
is (sending PATCH or POST, and handling markers
list of items, (that is the reason why I store Uuid
in one of EditState
. so we have local snapiness that Elm is giving us <3)
I was thinking of generalizing it, but first I want to get one more use case of similar form and then I will maybe try to think about it more abstractly 8)
I am aware that your use case is probably orders of magnitude more complicated that this piece right here, but still, I really think it is really important to have concrete requirements, because they drive it more than anything else. Elm is beautiful because it can express requirements so elegantly 