package bonsai

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Functions that take bonsai values that contain t, and kicking off reads whenever those values change.

The arguments here are chosen to match the results from Bonsai_web_ui_form.Elements.File_picker. So you can do things like:

let%sub file_picker = Bonsai_web_ui_form.Elements.File_select.single () in
let%sub file_from_form =
  let%arr file_picker = file_picker in
  Bonsai_web_ui_form.value file_picker |> Or_error.ok
in
let%sub result = Bonsai_web_ui_file.Read_on_change.create_single_opt file_from_form in
match%sub result with
| None -> Bonsai.const None
| Some (filename, (Bonsai_web_ui_file.Read_on_change.Status.Starting | In_progress _))
  ->
  let%arr filename = filename in
  Some (filename, "file still loading")
| Some (filename, Complete (Error e)) ->
  let%arr e = e
  and filename = filename in
  Some (filename, Error.to_string_hum e)
| Some (filename, Complete (Ok contents)) ->
  let%arr filename = filename
  and contents = contents in
  Some (filename, contents)

NOTE: these computations are not safe for use in Tangle as internally they require a model which cannot be of_sexp'd.

module Status : sig ... end
val create_single_opt : t option Bonsai.Value.t -> (Core.Filename.t * Status.t) option Bonsai.Computation.t
OCaml

Innovation. Community. Security.