lustre_routed

Lustre routed is a helper library for Lustre that helps create single-page-applications with the JS history routing API. It allows you to create applications with different routes without having a full-page refresh between the routes.

Lustre routed is based on the (currently experimental) v4.0 – in order to use it you will need to peg your Lustre version to ~> 4.0.0-rc.2 or later. Use in production at your own risk.

Types

When a route is passed to your view and loader functions it will be a list of strings. The path is split by its forward slashes, so that “/my/cool/route” gets split to [“my”, “cool”, “route”].

pub type Route =
  List(String)

The internal action/message type which is used by the routed application.

pub opaque type RoutedAction(orig_action)

The internal state/model which is used by the routed application to track its own route state as well as your own state.

pub opaque type RoutedModel(model)

Functions

pub fn go_to(route: String) -> RoutedAction(a)

Used to push a new route into the browser’s history stack.

pub fn listen_for_navigation(
  handler: fn(Action(RoutedAction(a), ClientSpa)) -> Nil,
) -> fn(Action(RoutedAction(a), ClientSpa)) -> Nil

Register your application’s handler to listen for changes in the browser’s history when the user hits the forward or backward buttons.

pub fn perform(action: a) -> RoutedAction(a)

Used to dispatch an action to your own internal state.

pub fn redirect(route: String) -> RoutedAction(a)

Used to replace the current route in the browser’s history.

pub fn routed_application(
  init: fn(a) -> #(b, Effect(RoutedAction(c))),
  update: fn(b, c) -> #(b, Effect(RoutedAction(c))),
  loader: fn(List(String), b) -> Effect(RoutedAction(c)),
  view: fn(List(String), b) -> Element(RoutedAction(c)),
) -> App(a, RoutedModel(b), RoutedAction(c))

Creates a lustre application which uses history-based routing.

Search Document