Module Brr_note.Elr

Reactive DOM elements.

Warning. Reactive DOM element mutators (rset_at, rset_children, etc.) and definers (def_at, def_children, etc.) use Note loggers to perform their action. To prevent memory leaks, these loggers, and thus their action, automatically get destroyed whenever the element is removed from the HTML DOM.

Children

val set_children : Brr.El.t -> on:Brr.El.t list Note.event -> unit

set_children e ~on sets e's children with the value of on whenever it occurs.

val def_children : Brr.El.t -> Brr.El.t list Note.signal -> unit

def_children e cs defines e's children over time with the value of signal cs. Warning. This assumes cs is the only entity interacting with the children.

Attributes and properties

val set_at : Brr.At.name -> on:Jstr.t option Note.event -> Brr.El.t -> unit

set_at a ~on e sets attribute a of e with the value of e whenever it occurs. If the value is None this removes the attribute.

val def_at : Brr.At.name -> Jstr.t option Note.signal -> Brr.El.t -> unit

def_at a v e defines the attribute a of e over time with the value of v. Whenever the signal value is None, the attribute is removed. Warning. This assumes v is the only entity interacting with that attribute.

val set_prop : 'a Brr.El.Prop.t -> on:'a Note.event -> Brr.El.t -> unit

set_prop p ~on e sets property p of e to the value of on whenever it occurs.

val def_prop : 'a Brr.El.Prop.t -> 'a Note.signal -> Brr.El.t -> unit

def_prop p v e defines the property p of e over time with the value of v. Warning. This assumes v is the only entity interacting with that property.

Classes

val set_class : Jstr.t -> on:bool Note.event -> Brr.El.t -> unit

set_class a ~on e sets the membership of e to class e with the value of on whenever it occurs.

val def_class : Jstr.t -> bool Note.signal -> Brr.El.t -> unit

rdef_class a b e defines the membership of e to class e over time with the value of b. Warning. This assumes b is the only entity interacting with that class.

Style

val set_inline_style : ?⁠important:bool -> Brr.El.Style.prop -> on:Jstr.t Note.event -> Brr.El.t -> unit

set_style ~important p ~on e sets the inline style property p of e to the value of on whenever it occurs with priority important (defaults to false).

val def_inline_style : ?⁠important:bool -> Brr.El.Style.prop -> Jstr.t Note.signal -> Brr.El.t -> unit

def_style p v e sets the inline style property p of e over time with the value of v. Warning. This assumes v is the only entity interacting with that property.

Focus

val set_has_focus : on:bool Note.event -> Brr.El.t -> unit

set_focus e ~on sets e's focus with the value of on whenever it occurs.

val def_has_focus : bool Note.signal -> Brr.El.t -> unit

def_focus e v defines the focus of e over time with the value of v. Warning. This asumes v is the only entity interacting with e's focus.

Life-cycle callbacks

The browser document is watched for changes via a global MutationObserver. Whenever an element is added in the HTML DOM, its on_add callbacks get called and disposed. Whenever an element is removed from the HTML DOM, on_rem callbacks get called and disposed. A element is deemed part of the HTML DOM if its root node is the browser document.

val on_add : (unit -> unit) -> Brr.El.t -> unit

on_add f e references f until e is inserted in the HTML DOM, at which point f () is invoked.

val on_rem : (unit -> unit) -> Brr.El.t -> unit

on_rem f e references f until e is removed from the HTML DOM, at which point f () is invoked.

Note loggers

val call : ('a -> Brr.El.t -> unit) -> on:'a Note.event -> Brr.El.t -> unit

call f ~on e calls f on e with the value of e whenever on occurs. The underlying logger is held by e.

val hold_logr : Brr.El.t -> Note.Logr.t -> unit

hold_logr e l lets e hold logger l and destroy it via on_rem once e is removed from the document.

val may_hold_logr : Brr.El.t -> Note.Logr.t option -> unit

may_hold_logr e l is like hold_logr but does nothing on None.