package virtual_dom

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

This module provides a more opinionated way to use html5-history; it's a thin wrapper over the above.

module type Uri_routing = sig ... end

The Uri_routing module is common to your server and your client. The server needs to call it because it should only serve up your client.html if routing succeeds. You shouldn't unconditionally serve the homepage and rely on the client javascript to filter out bad uris, because it means you'll serve up junk for favicon.ico and robots.txt etc.

module type History_state = sig ... end
type _ t
val init_exn : ?log_s:(Core.Sexp.t -> unit) -> (module History_state with type t = 's and type uri_routing = 'u) -> (module Uri_routing with type t = 'u) -> on_bad_uri:[ `Raise | `Default_state of 's ] -> 's t

You can only call init_exn or Opinionated.init_exn once (see above).

val current : 's t -> 's
val changes_bus : 's t -> ('s -> unit, Core.read) Bus.t
val update : 's t -> 's -> unit

We will "push" a state if the Uri_routing.t changes as a result of this update (i.e., to_uri_routing previous_state <> to_uri_routing new_state), and use "replace" otherwise. This matches the intuition that new history states are created when the address bar changes (but the current state can be updated if the things you're looking at within that view change).

val replace : 's t -> 's -> unit

Like update, but does not "push" a state even if the Uri_routing.t changes as a result of this update.

val sync_to_bonsai : 's t -> extra_bus:('e -> unit, Core.read) Bus.t -> get_state:('e -> ('s, [ `Uninitialised ]) Core.Result.t) -> schedule_navigate_to:('s -> unit) -> unit

extra_bus is Bonsai_web.Start.Handle.extra; get_state projects the history state out of your "extra" value, and schedule_navigate_to should use whatever combination of Handle.inject_incoming or kicking off async jobs is required to navigate to the new model and start any processes required to initialise it (e.g., by loading some data from the server).

get_state is allowed to return an error (we just ignore the update) in case you need to have some temporary startup state in your model. It's just a convenience.

We do not call schedule_navigate_to for the initial state.

OCaml

Innovation. Community. Security.