package virtual_dom

  1. Overview
  2. Docs
OCaml bindings for the virtual-dom library

Install

Dune Dependency

Authors

Maintainers

Sources

virtual_dom-v0.16.0.tar.gz
sha256=0c6f07894dce56db88d46b3aa4f2cad1a84aeaf0009560a285492f9f2959d565

doc/virtual_dom/Virtual_dom/Vdom/Node/index.html

Module Vdom.NodeSource

Sourcemodule Element : sig ... end

The values associated with an Element and element like nodes. (that is in practice all nodes that aren't just text).

Sourcetype widget
Sourcetype t =
  1. | None
  2. | Text of Base.string
  3. | Element of Element.t
  4. | Widget of widget
  5. | Lazy of {
    1. key : Base.string Base.option;
    2. t : t Base.Lazy.t;
    }
Sourcemodule Widget : sig ... end
type node_creator := ?key:Base.string -> ?attrs:Virtual_dom__.Attr.t Base.list -> t Base.list -> t
type node_creator_childless := ?key:Base.string -> ?attrs:Virtual_dom__.Attr.t Base.list -> Base.unit -> t
Sourcemodule Aliases : sig ... end
Sourceval none : t
Sourceval text : Base.string -> t
Sourceval textf : ('a, Base.unit, Base.string, t) Base.format4 -> 'a
Sourceval button : node_creator
Sourceval datalist : node_creator
Sourceval details : node_creator
Sourceval fieldset : node_creator
Sourceval legend : node_creator
Sourceval header : node_creator
Sourceval textarea : node_creator
Sourceval select : node_creator
Sourceval optgroup : node_creator
Sourceval option : node_creator
Sourceval label : node_creator
Sourceval section : node_creator
Sourceval strong : node_creator
Sourceval blockquote : node_creator
Sourceval summary : node_creator
Sourceval iframe : node_creator
Sourceval table : node_creator
Sourceval tbody : node_creator
Sourceval thead : node_creator
Sourceval sexp_for_debugging : ?indent:Base.int -> Base.Sexp.t -> t
Sourceval lazy_ : ?key:Base.string -> t Base.Lazy.t -> t
Sourceval inner_html : ?override_vdom_for_testing:t Base.Lazy.t -> tag:Base.string -> attrs:Virtual_dom__.Attr.t Base.list -> this_html_is_sanitized_and_is_totally_safe_trust_me:Base.string -> Base.unit -> t

This function can be used to build a node with the tag and html content of that node provided as a string. If this function was called with ~tag:"div" ~attrs:[] ~this_html...:"<b> hello world</b>" then the resulting node would be <div><b> hello world </b></div>

For totally sanitized content strings, this is fine; but if a user can influence the value of content and you don't have a sanitizer, they can inject code into the page, so use with extreme caution!

Sourceval inner_html_svg : ?override_vdom_for_testing:t Base.Lazy.t -> tag:Base.string -> attrs:Virtual_dom__.Attr.t Base.list -> this_html_is_sanitized_and_is_totally_safe_trust_me:Base.string -> Base.unit -> t

Same as inner_html but for svg elements

Sourceval input_deprecated : node_creator

Use input instead of input_deprecated. The only difference is that input does not accept a list of child nodes, but input_deprecated does. HTML <input> tags are not meant to have any child elements.

  • deprecated [since 2022-05] use [input] instead
Sourceval create : Base.string -> node_creator

key is used by Virtual_dom as a hint during diffing/patching

Sourceval create_svg : Base.string -> node_creator

Like create but for svg nodes (i.e. all to be placed inside <svg> tag). This is needed as browsers maintain separate namespaces for html and svg, and failing to use the correct one may result in delayed redraws.

Creates a new browser DOM element from a virtual-dom node. Note that calling this function will give you a brand new element, which you then have to put into the DOM yourself. Thus, you should probably not be calling this very often, since Bonsai and Incr_dom both take care calling this function on the top-level view node.

The one situation where to_dom is useful for the typical user is with the Widget API, since building a Widget entails generating the browser DOM element.

Sourceval to_raw : t -> Virtual_dom__.Raw.Node.t
Sourceval widget : ?vdom_for_testing:t Base.Lazy.t -> ?destroy: ('s -> Js_of_ocaml.Dom_html.element as 'e Js_of_ocaml.Js.t -> Base.unit) -> ?update:('s -> 'e Js_of_ocaml.Js.t -> 's * 'e Js_of_ocaml.Js.t) -> id:('s * 'e Js_of_ocaml.Js.t) Base.Type_equal.Id.t -> init:(Base.unit -> 's * 'e Js_of_ocaml.Js.t) -> Base.unit -> t

Creates a Node.t that has fine-grained control over the Browser DOM node.

Callbacks =========

init: Returns a Browser DOM Node and a widget state object. The Browser DOM node is mounted into the dom in the location where the Node.t object would otherwise be.

update: Given the previous Browser DOM Node and state, makes any changes necessary to either and returns a new state and Browser DOM Node.

destroy: Called when this Node.t is removed from the Virtual_dom. Performs any necessary cleanup.

Other =====

The id is used to compare widgets, and is used to make sure that the state from one widget doesn't get interpreted as the state for another. Otherwise, you would be able to implement Obj.magic using this API.

WARNING: While other Virtual_dom APIs shield the application from script injection attacks, the Widget.create function allows a developer to bypass these safeguards and manually create DOM nodes which could allow an attacker to change the behavior of the application or exfiltrate data.

In using this API, you are being trusted to understand and follow security best-practices.

Sourceval widget_of_module : (module Widget.S with type Input.t = 'input) -> ('input -> t) Base.Staged.t

widget_of_module is very similar to widget, but it pulls all of the callbacks out into a first-class module. Read the comment for widget to learn more.

It is very important that you call widget_of_module exactly once for any "widget class" that you want to construct. Otherwise, the nodes created by it won't be comparable against one another and the widget-diffing will just run destroy, init, destroy, init over and over.

Sourcemodule Patch : sig ... end
Sourcemodule Expert : sig ... end
OCaml

Innovation. Community. Security.