illustrious/server
Types
The initializer function takes in the path & the app state and returns a JSON value which can be serialized and sent to the client to initialize the application state before the first client render
pub type Initializer(context, error) =
fn(Path, context) -> Result(Json, error)
A generated server-side application
pub opaque type ServerApp(context, model, action, error)
The options necessary to initialize the client-side lustre app
pub type ServerAppBuilder(context, model, action, error) {
ServerAppBuilder(
view: illustrious.View(model, action),
html_headers: illustrious.View(model, action),
default_model: model,
updater: state.Updater(model, action),
decoder: state.Decoder(action),
initializer: Initializer(context, error),
loader: ServerLoader(context, error),
error_serializer: fn(error) -> String,
)
}
Constructors
-
ServerAppBuilder( view: illustrious.View(model, action), html_headers: illustrious.View(model, action), default_model: model, updater: state.Updater(model, action), decoder: state.Decoder(action), initializer: Initializer(context, error), loader: ServerLoader(context, error), error_serializer: fn(error) -> String, )
Arguments
-
view
The function which takes in the application from the path and model, and renders the application
-
html_headers
A view of html headers. Used to render inside the
<head>
tag during server-side rendering. -
default_model
The initial application state before any baked data is processed
-
updater
The function used to update application state based on the previous model and an action being performed
-
decoder
The function which transforms a JSON payload (in the form of initializer data or page loader data)
-
initializer
The function called when a page is first loaded, which takes in the application path and context, in order to initialize the application state.
Returns a Result containing a Json object (or a Json array of objects) which can be deserialized using the
decoder
and applied in order to the app state using theupdater
to generate the initial application state upon first loading a route.If the Result is instead an
Error
, the contained error is serialized into a string using theerror_serializer
function. -
loader
The function called whenever a route change occurs, which takes in the application path and context, in order to send data to the client to update its state.
Returns a Result containing a Json object (or a Json array of objects) which can be deserialized using the
decoder
and applied in order to the app state using theupdater
to generate the new application state upon changing to a new route.If the Result is instead an
Error
, the contained error is serialized into a string using theerror_serializer
function. -
error_serializer
A function which takes in any errors generated by the
initializer
orloader
functions and returns aString
-
The server loader function takes in the path and returns a JSON value which can be used to populate the server state and also serialized and sent to the client in order to initialize the state there as well
pub type ServerLoader(context, error) =
fn(Path, context) -> Result(Json, error)
The result of calling a ServerApp
’s request_handler
function.
pub type ServerResult(action) {
View(element.Element(IllustriousAction(action)))
Data(Json)
ServerError(String)
NoResult
}
Constructors
-
View(element.Element(IllustriousAction(action)))
The type of result which comes from the request matching a page route.
-
Data(Json)
The type of result sent whenever a request comes in that calls the app’s
loader
function, which gets sent to the client to update the model. -
ServerError(String)
The type of result which comes from an error occuring during initialization, rendering, or loading.
-
NoResult
The type of result when no route is matched.
Functions
pub fn build_app(
builder: ServerAppBuilder(a, b, c, d),
) -> ServerApp(a, b, c, d)
Create a ServerApp
based on the builder passed in.
pub fn handle_request(
app: ServerApp(a, b, c, d),
method: Method,
path: List(String),
body: String,
context: a,
) -> ServerResult(c)
The function to handle a request sent to the server applicaiton.