A “model”, in an Ema app, represents all the data used to render the site. The model is also used (in IsRoute
), optionally, to encode the route types.
Taking the blog site example from Example route, our model would look something like the following:
data Model = Model
{ modelSiteTitle :: Text
, modelBlogPosts :: Map Slug (Date, Pandoc)
}
The idea here is that in order to render our weblog, we only need a value of type Model
, and we can render it without reading anything from the environment (doing IO).
Models impact two places:
-
RouteModel
ofIsRoute
associates a route type with a model type. This enables Route Prism (androuteUniverse
) to accept that model value as an argument. -
In EmaSite typeclass,
siteInput
can now return this model value (and it can be time-varying if using a Dynamic), as well assiteOutput
can take the model value so as to render the site based on it.
Useful libraries
- ixset-typed - for database-like querying into in-memory model values
-
unionmount
- mounting local files into Haskell in-memory model with change updates.