🥮 mooncakes.io

    XiLaiTL/moobile/vendor/rabbita/vdom does not have a README file

    Children

    pub(all) enum Children[T] {
    Array(Array[T])
    Map(Map[String, T])
    RawHtml(String)
    }

    Event

    #external
    pub type Event

    ★ moobile 改造:事件值是后端无关的不透明类型,不再别名为 @dom.Event。

    为什么必须改:原来的别名让 Props.handlers 的公开签名带着 @dom, 而 @dom 是 js-only 的 DOM 绑定包。后果是外部包既命名不了这个类型、 也换不掉它 —— 这正是当初不得不加 Props::each_handler 的原因。

    现在:DOM 后端在监听器边界处把 @dom.Event 强转进来(dom_event), React 后端直接把合成事件透传。语义上两边都是"一个事件值", 谁也不需要认识对方的具体类型。

    Props

    pub struct Props {
    handlers : Map[String, (Event, &
    Scheduler
    ) -> Unit]
    attrs : Map[String, String]
    props : Map[String,
    Variant
    ]
    styles : Map[String,
    StyleValue
    ]
    }

    Props::attr

    fn Props::attr(self : Props, key : String, value : String) -> Props

    设置字符串属性(placeholder / value 这类)。

    Props::attrs_map

    fn Props::attrs_map(self : Props) -> Map[String, String]

    字符串属性表(只读)。

    Props::copy

    fn Props::copy(self : Props) -> Props

    Props::each_handler

    fn Props::each_handler(self : Props, scheduler : &
    Scheduler
    , f : (String, (Event) -> Unit) -> Unit) -> Unit

    把事件处理器包成"只吃一个 JS 值"的形式,供非 DOM 后端(React Native)调用。

    Props::empty

    fn Props::empty() -> Props

    空属性集。

    Props::new

    Props::on

    fn Props::on(self : Props, event : String, f : (Event, &
    Scheduler
    ) -> Unit) -> Props

    注册事件处理器。Event 由签名提供,调用方不必命名它。

    Props::prop

    fn Props::prop(self : Props, key : String, value :
    Variant
    ) -> Props

    设置非字符串属性(bool / int / float)。

    Props::props_map

    非字符串属性表(只读)。

    Props::styles

    合并一份类型化样式。

    Props::styles_map

    fn Props::styles_map(self : Props) -> Map[String,
    StyleValue
    ]

    类型化样式表(只读)。

    VDom

    type VDom

    VDom::initialize

    fn VDom::initialize(vnode : VNode, scheduler : &
    Scheduler
    , target_element_id? : String) -> VDom

    VDom::initialize_with_hydration

    fn VDom::initialize_with_hydration(vnode : VNode, scheduler : &
    Scheduler
    ) -> VDom

    VDom::to_string

    fn VDom::to_string(self : VDom) -> String

    VDom::update

    fn VDom::update(self : VDom, root : VNode, scheduler : &
    Scheduler
    ) -> Unit

    VNode

    pub enum VNode {
    Elem(String, Props, Children[VNode], namespace_uri~ : String?)
    Text(String)
    Frag(Array[VNode])
    Thunk(Int, () -> VNode)
    }

    impl Eq for VNode

    VNode::document

    fn VNode::document(props : Props, head : VNode, body : VNode) -> VNode

    VNode::elem

    fn VNode::elem(tag : String, props : Props, children : Children[VNode], namespace_uri? : String) -> VNode

    VNode::fragment

    fn VNode::fragment(childs : Array[VNode]) -> VNode

    fn VNode::link(props : Props, children : Children[VNode], escape? : Bool) -> VNode

    VNode::text

    fn VNode::text(s : String) -> VNode

    as_dom_event

    Event → @dom.Event。DOM 侧的辅助函数(从事件里取值)使用。

    server_side_render

    fn server_side_render(render : () -> VNode) -> String