package virtual_dom
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=812711b4d5ce634a413580cd7096482de8d71abec9ae37bb01f7c0dcec2968ec
doc/virtual_dom.html5_history/Html5_history/Opinionated/index.html
Module Html5_history.Opinionated
Source
This module provides a more opinionated way to use html5-history; it's a thin wrapper over the above.
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.
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).
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).
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.