package incr_dom_interactive
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=523b9c27e5103717db4e40b43f8124da2863ab0273e6e1ef1ba8577b44a72523
doc/incr_dom_interactive/Incr_dom_interactive/Primitives/index.html
Module Incr_dom_interactive.PrimitivesSource
type 'a primitive =
?attrs:Incr_dom_interactive__.Import.Vdom.Attr.t list ->
?id:string ->
unit ->
'a tid lets you specify a value for the "id" attribute of the DOM node. It doesn't affect the behavior of this library (unless you accidentally create two nodes with the same id), but it might be useful if you want to refer to the node elsewhere.
options is a list of tuples (label, value). label is what will be displayed to the user in the dropdown. value is what will be produced by the Interactive.t when that option is selected by the user.
init is the 0-based index of the option which is initially selected. It defaults to 0.
Raises when options is empty or init >= List.length options.
dropdown_with_blank_exn is a wrapper around dropdown_exn which adds a blank option to the dropdown that produces None. It is otherwise the same as dropdown_exn.
If you don't provide a value for init, the initial value for the dropdown will be the blank option which produces None.
Raises when init >= List.length options.
val create :
init:'a ->
render:
(inject:('a -> unit Incr_dom_interactive__.Import.Vdom.Effect.t) ->
value:'a Incr_dom.Incr.t ->
Incr_dom_interactive__.Import.Vdom.Node.t list Incr_dom.Incr.t) ->
'a tcreate allows you to create your own primitives. init is the initial value of the Interactive.t. inject is how the users of your primitive tell it what to do with new values. In your event handler, you should call it and supply the new value of the primitive.
You should use value to determine the value of your primitive. For example, if your primitive is a checkbox, you should do this:
let render ~inject ~value =
let open Incr.Let_syntax in
let%map is_checked = value in
let node =
if is_checked
then (* ... create a [Node.t] representing a checked checkbox ... *)
else (* ... create a [Node.t] representing an unchecked checkbox ... *)
in
...You should not use init to determine the value. value will initially be the same as init, but it might be different if the field is modified, then stops being rendered, then is rendered again. In this case, we want the user's input to be preserved. But if you use init to fill in the initial value, the user's input will be discarded in this case.
For an example, check the implementation of Primitives.text.