package bonsai
A library for building dynamic webapps, using Js_of_ocaml
Install
Dune Dependency
Authors
Maintainers
Sources
bonsai-v0.16.0.tar.gz
sha256=1d68aab713659951eba5b85f21d6f9382e0efa8579a02c3be65d9071c6e86303
doc/bonsai.uri_parsing/Uri_parsing/Parser/Record/index.html
Module Parser.Record
Source
Path order is one of the scarier parts of the API and is explained further in the explanation for S.path_order
.
Makes a 'a t
where 'a is a record.
When dealing with nested records, namespaces are automatically inferred, but can be overriden with the optional namespace parameter.
Example:
module Nested = struct
type t =
{ foo : int
; bar : int
}
[@@deriving typed_fields, sexp, equal]
let parser_for_field : type a. a Typed_field.t -> a Parser.t = function
| Foo -> Parser.from_query_required Value_parser.int
| Bar -> Parser.from_query_required Value_parser.int
;;
let path_order = []
end
module My_url = struct
type t =
{ a : Nested.t
; b : Nested.t
}
[@@deriving typed_fields, sexp, equal]
let parser_for_field : type a. a Typed_field.t -> a Parser.t = function
| A -> Parser.Record.make (module Nested)
| B -> Parser.Record.make (module Nested)
;;
let path_order = []
end
let%expect_test _ =
let parser = Parser.Record.make (module My_url) in
Parser.check_ok_and_print_urls_or_errors parser;
[%expect
{|
URL parser looks good!
┌───────────────────────────────────────────────────┐
│ All urls │
├───────────────────────────────────────────────────┤
│ /?a.bar=<int>&a.foo=<int>&b.bar=<int>&b.foo=<int> │
└───────────────────────────────────────────────────┘ |}]
;;
(*Doing this instead results in: *)
let parser_for_field : type a. a Typed_field.t -> a Parser.t = function
| A -> Parser.Record.make ~namespace:[ "my_a" ] (module Nested)
| B -> Parser.Record.make ~namespace:[ "my_b" ] (module Nested)
;;
let%expect_test _ =
Parser.check_ok_and_print_urls_or_errors parser;
[%expect
{|
URL parser looks good!
┌───────────────────────────────────────────────────────────────┐
│ All urls │
├───────────────────────────────────────────────────────────────┤
│ /?my_a.bar=<int>&my_a.foo=<int>&my_b.bar=<int>&my_b.foo=<int> │
└───────────────────────────────────────────────────────────────┘ |}]
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>