package bonsai

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
module Components : sig ... end
module Original_components := Components
module type T = sig ... end
module type S = sig ... end

Types that implement S can be parsed from a url and unparsed into a url.

module type S_via_sexp = sig ... end

Types that are sexpable can be turned a URL by storing the value as a sexp in a query parameter.

type 'a t
val create_exn : (module S with type t = 'a) -> fallback:'a -> 'a t

Creating a url-var involves passing in a module that implements S, but also a fallback value which will be used if S.parse_exn throws.

val set : ?how:[ `Push | `Replace ] -> 'a t -> 'a -> unit

set updates the contents of the url-var as well as the current browser location. When how is `Push (which is the default), it will add a new entry to the top of the browser's history stack, but `Replace will cause it to replace the top entry of the history stack with the new URL.

val update : ?how:[ `Push | `Replace ] -> 'a t -> f:('a -> 'a) -> unit

update is like set, but gives you access to the previous value of the url right before setting it.

val update_effect : ?how:[ `Push | `Replace ] -> 'a t -> f:('a -> 'a) -> unit Bonsai_web.Effect.t
val get : 'a t -> 'a
val value : 'a t -> 'a Bonsai_web.Value.t
val incr : 'a t -> 'a Ui_incr.t
val set_effect : ?how:[ `Push | `Replace ] -> 'a t -> 'a -> unit Bonsai_web.Effect.t

By asking for the Url_var.t's effect, you get a function that can be easily threaded through your components and triggered inside an action-application or inside of an event listener.

type 'a url_var = 'a t
module Typed : sig ... end

This module allows you to define your Url_var out of an OCaml type similar to the Typed Forms API. The module provides nice features like static analysis of your parser, ambiguity checking and functions to make backwards compatibility easier. Please read ../README.mdx first to make reading this MLI easier.

module For_testing : sig ... end
OCaml

Innovation. Community. Security.