package incr_dom_sexp_form

  1. Overview
  2. Docs

Module Incr_dom_sexp_formSource

Sourcetype 'a t
Sourcemodule Init : sig ... end

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

Sourceval to_interactive : init:'a Init.t -> 'a t -> 'a Core.Or_error.t Incr_dom_interactive.t
Sourcemodule 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.

Sourcemodule 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.

Sourcemodule 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.

Sourcemodule Primitives : sig ... end
Sourceval 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.

Sourceval 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.

Sourcemodule 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.