pream/vnode

Types

vnode property — either an attribute (any gleam value, serialized downstream in ffi) or an event handler. handlers are camelCased and prefixed with on_ in ffi

pub type Prop {
  Attr(key: String, value: dom.Native)
  Handler(event: String, handle: fn(dom.Event) -> Nil)
}

Constructors

  • Attr(key: String, value: dom.Native)

    NOTE: a prop can be any gleam value we’re swallowing the type here and handle it downstram in ffi. this is done to make the render API simple

  • Handler(event: String, handle: fn(dom.Event) -> Nil)

child of a vnode — one of four variants: static element, static text, reactive element, or reactive text. use the constructors below (e.g. text, element, reactive, reactive_text) to build values of this type.

pub type VChild {
  Element(VNode)
  Text(String)
  Reactive(signal.Signal(VNode))
  ReactiveText(signal.Signal(String))
}

Constructors

virtual dom node — same shape as the output of preact’s h(). built up via small composable helpers below, then handed to pream.to_preact

pub opaque type VNode

Values

pub fn a() -> VNode
pub fn alt(vnode: VNode, text: String) -> VNode
pub fn article() -> VNode
pub fn br() -> VNode
pub fn button() -> VNode
pub fn checked(vnode: VNode) -> VNode
pub fn child(vnode: VNode, child: VChild) -> VNode

appends a single child

pub fn children(vnode: VNode, children: List(VChild)) -> VNode

appends a list of children

pub fn class(vnode: VNode, name: String) -> VNode
pub fn disabled(vnode: VNode) -> VNode
pub fn div() -> VNode
pub fn element(node: VNode) -> VChild

wraps a vnode as a child element

pub fn empty() -> VNode

renders nothing — mapped to preact’s null in ffi

pub fn footer() -> VNode
pub fn form() -> VNode
pub fn fragment() -> VNode

https://npmx.dev/package-docs/preact/v/10.29.2#function-fragment a fragment vnode — used to return multiple sibling children without a wrapper element

pub fn h1() -> VNode
pub fn h2() -> VNode
pub fn h3() -> VNode
pub fn h4() -> VNode
pub fn h5() -> VNode
pub fn h6() -> VNode
pub fn header() -> VNode
pub fn hr() -> VNode
pub fn href(vnode: VNode, url: String) -> VNode
pub fn id(vnode: VNode, name: String) -> VNode
pub fn img() -> VNode
pub fn input() -> VNode
pub fn label() -> VNode
pub fn li() -> VNode
pub fn main() -> VNode
pub fn map_signal(
  s: signal.Signal(a),
  render: fn(a) -> VChild,
) -> VChild

maps a signal through render — each value is wrapped as a VChild inside a fragment. the result is itself a reactive VChild.

pub fn name(vnode: VNode, name: String) -> VNode
pub fn nav() -> VNode
pub fn new(tag: String) -> VNode

https://npmx.dev/package-docs/preact/v/10.29.2#function-h creates an empty vnode with the given tag and no props or children — equivalent to <tag />

pub fn ol() -> VNode
pub fn on(
  vnode: VNode,
  event: String,
  handle: fn(dom.Event) -> Nil,
) -> VNode

attaches an event handler. the event name is camelCased and prefixed with on_ in ffi (e.g. click becomes onClick)

pub fn option_tag() -> VNode
pub fn p() -> VNode
pub fn placeholder(vnode: VNode, text: String) -> VNode
pub fn prop(vnode: VNode, key: String, value: a) -> VNode

sets an attribute on the vnode. any gleam value is accepted — stringification/serialization is deferred to the ffi at render time

pub fn reactive(s: signal.Signal(VNode)) -> VChild

creates a reactive element child from a signal

pub fn reactive_text(s: signal.Signal(String)) -> VChild

creates a reactive text child from a signal

pub fn required(vnode: VNode) -> VNode
pub fn role(vnode: VNode, name: String) -> VNode
pub fn section() -> VNode
pub fn select() -> VNode
pub fn span() -> VNode
pub fn src(vnode: VNode, url: String) -> VNode
pub fn table() -> VNode
pub fn td() -> VNode
pub fn text(content: String) -> VChild

creates a static text child

pub fn text_with(content: String, args: List(String)) -> VChild

creates a static text child with positional formatting — each {} is replaced with the next value from the list

pub fn textarea() -> VNode
pub fn th() -> VNode
pub fn title(vnode: VNode, text: String) -> VNode
pub fn tr() -> VNode
pub fn type_(vnode: VNode, name: String) -> VNode
pub fn ul() -> VNode
pub fn unless(condition: Bool, render: fn() -> VChild) -> VChild

renders render when condition is False, otherwise returns an empty text node

pub fn value_int(vnode: VNode, val: Int) -> VNode
pub fn value_string(vnode: VNode, val: String) -> VNode
pub fn when(condition: Bool, render: fn() -> VChild) -> VChild

renders render when condition is True, otherwise returns an empty text node

pub fn when_signal(
  s: signal.Signal(Bool),
  render: fn() -> VChild,
) -> VChild

renders render when the signal value is True, otherwise returns an empty fragment. the result is itself a reactive VChild.

pub fn when_some(
  option: option.Option(a),
  render: fn(a) -> VChild,
) -> VChild

renders render when the option is Some, otherwise returns an empty text node

Search Document