package incr_dom_sexp_form

  1. Overview
  2. Docs
type 'a t
module Init : sig ... end

This is a module for building forms that allow the user to edit complicated types (for example, configs).

val to_interactive : init:'a Init.t -> 'a t -> 'a Core.Or_error.t Incr_dom_interactive.t
module Case : sig ... end

A 'a Case.t is implemented as a 'a Sexp_form.t. When you create a case from a variant constructor for variant Foo.t, say a constructor for type int * string, you get a (int -> string -> Foo.t) Case.t.

module Record_builder : sig ... end

('record, 'a) Record_builder.t is implemented as a 'a Sexp_form.t. The 'record only exists for additional type safety.

module Record_field : sig ... end

('record, 'a) Record_field.t is implemented as a 'a Sexp_form.t. The 'record only exists for additional type safety.

module Primitives : sig ... end
val map : 'a t -> a_to_b:('a -> 'b) -> b_to_a:('b -> 'a) -> sexp_of_a:('a -> Core.Sexp.t) -> b_of_sexp:(Core.Sexp.t -> 'b) -> 'b t

To map from 'a t to 'b t, we need to be able to parse default values of type 'b.

Since we parse default values as sexps, this entails some conversion back and forth.

If a_to_b throws, this function will catch it and display the error to the user.

val map_that_can_fail : 'a t -> a_to_b:('a -> 'b Core.Or_error.t) -> b_to_a:('b -> 'a) -> sexp_of_a:('a -> Core.Sexp.t) -> b_of_sexp:(Core.Sexp.t -> 'b) -> 'b t

If this returns an error, the error will be displayed before the form element.

If a_to_b throws, this function will catch it and display the error to the user.

module Unsafe : sig ... end

This module is "Unsafe" because it relies on the user to ensure that when they map from 'a to 'b, 'a and 'b have the same sexp representation.

val validate : where:[ `Before | `After ] -> 'a t -> f:('a -> unit Core.Or_error.t) -> 'a t

Validates the value in the form, displaying the provided error if it is invalid. where indicates whether the error should be displayed before or after the form element. It's recommended to use `After for errors which are right next to the area where the user inputs the data, and `Before for errors in complicated types which comprise many input fields.

val validate_interactive : where:[ `Before | `After ] -> 'a t -> 'b Incr_dom_interactive.t -> f:('a -> 'b -> unit Core.Or_error.t) -> 'a t

Same as validate, but more suited for validating properties which depend on external, changing state.

Note that an Incr can be converted to an Interactive using Interactive.of_incr.

val handle_error : where:[ `Before | `After ] -> 'a Core.Or_error.t t -> 'a t

handle_error displays the error, if there is one. If there is no error, it does nothing.

validate is a wrapper around handle_error.

val test : form:'a t -> value:'a -> sexp_of_t:('a -> Core.Sexp.t) -> equal:('a -> 'a -> bool) -> on_failure:[ `Print | `Raise ] -> unit

Verifies that the provided form can parse value. Intended for expect tests.

val test_list : form:'a t -> values:'a list -> sexp_of_t:('a -> Core.Sexp.t) -> equal:('a -> 'a -> bool) -> on_failure:[ `Print | `Raise ] -> unit

For convenience -- it just calls test for each value.

val test_sequence : form:'a t -> values:'a Core.Sequence.t -> sexp_of_t:('a -> Core.Sexp.t) -> equal:('a -> 'a -> bool) -> on_failure:[ `Print | `Raise ] -> unit

For convenience -- it just calls test for each value.

OCaml

Innovation. Community. Security.