Sign in

    respo

    A tiny virtual DOM library

    virtual-dom
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    last year
    Downloads
    2K

    #Respo in MoonBit

    A tiny virtual DOM library ported from Respo.rs.

    Core ideas:

    • Hot reload friendly for better dev experience
    • Embraces types and autocompletion
    • States are stored in a single atom, which is a tree structure with a concept like cursor
    • Uni-directional data flow, dispatching is only allowed when user events occur
    • Effects are for DOM updates, rather than dispatching actions

    This project is in beta stage. APIs and structure are relatively stable.

    Areas that need further exploration:

    • Working with MoonBit immutable data structures

    #Usage

    moon add tiye/respo

    To use Respo, start with the boilerplate at https://github.com/Respo/respo-moonbit-workflow

    #License

    Apache-2.0

    ObscureState

    type ObscureState

    MoonBit does not allow trait object with Selfs, use ffi js value to bypass.

    RespoApp

    pub(all) struct RespoApp[Model] {
    store : Ref[Model]
    storage_key : String
    mount_target :
    Node

    }

    get basic App structure

    RespoApp::backup_model_beforeunload

    fn[Model : ToJson] RespoApp::backup_model_beforeunload(self : RespoApp[Model]) -> Unit

    backup store to local storage before unload

    RespoApp::render_loop

    fn[Model, ActionOp] RespoApp::render_loop(self : RespoApp[Model], renderer : () ->
    RespoNode
    [ActionOp] raise
    RespoCommonError
    , dispatch_action : (ActionOp) -> Unit raise
    RespoCommonError
    ) -> Unit

    RespoStatesTree

    pub(all) struct RespoStatesTree {
    backup : Json?
    cursor : Array[String]
    branches : Map[String, RespoStatesTree]
    // private fields
    }

    Respo maintains states in a tree structure, where the keys are strings, each child component "picks" a key to attach its own state to the tree, and it dispatches events to global store to update the state.

    RespoStatesTree::cast_branch

    RespoStatesTree::local_pair

    local state in component could be None according to the tree structure
    let (state, cursor): (LocalState, _) = states.local_pair();

    RespoStatesTree::path

    RespoStatesTree::pick

    fn RespoStatesTree::pick(self : RespoStatesTree, name : String) -> RespoStatesTree

    RespoStatesTree::set_in_mut

    fn RespoStatesTree::set_in_mut(self : RespoStatesTree, change : RespoUpdateState) -> Unit

    TODO prefer immutable update in future

    RespoUpdateState

    pub(all) struct RespoUpdateState {
    cursor : Array[String]
    data : ObscureState?
    backup : Json?
    }

    framework defined action for updating states branch

    code_fonts

    let code_fonts : String

    default_fonts

    let default_fonts : String

    fancy_fonts

    let fancy_fonts : String

    mark_need_rerender

    fn mark_need_rerender() -> Unit

    memo_once1

    fn[K : Eq, V] memo_once1(f : (K) -> V) -> ((K) -> V)

    Memoize a function with a single cache slot, taking one argument.

    memo_once2

    fn[K1 : Eq, K2 : Eq, V] memo_once2(f : (K1, K2) -> V) -> ((K1, K2) -> V)

    Memoize a function with a single cache slot, taking two arguments.

    memo_once3

    fn[K1 : Eq, K2 : Eq, K3 : Eq, V] memo_once3(f : (K1, K2, K3) -> V) -> ((K1, K2, K3) -> V)

    Memoize a function with a single cache slot, taking three arguments.

    memo_once4

    fn[K1 : Eq, K2 : Eq, K3 : Eq, K4 : Eq, V] memo_once4(f : (K1, K2, K3, K4) -> V) -> ((K1, K2, K3, K4) -> V)

    Memoize a function with a single cache slot, taking four arguments.

    memo_once5

    fn[K1 : Eq, K2 : Eq, K3 : Eq, K4 : Eq, K5 : Eq, V] memo_once5(f : (K1, K2, K3, K4, K5) -> V) -> ((K1, K2, K3, K4, K5) -> V)

    Memoize a function with a single cache slot, taking five arguments.

    memoize1

    fn[K : Hash + Eq, V] memoize1(f : (K) -> V) -> ((K) -> V)

    memoize2

    fn[K1 : Hash + Eq, K2 : Hash + Eq, V] memoize2(f : (K1, K2) -> V) -> ((K1, K2) -> V)

    memoize3

    fn[K1 : Hash + Eq, K2 : Hash + Eq, K3 : Hash + Eq, V] memoize3(f : (K1, K2, K3) -> V) -> ((K1, K2, K3) -> V)

    memoize4

    fn[K1 : Hash + Eq, K2 : Hash + Eq, K3 : Hash + Eq, K4 : Hash + Eq, V] memoize4(f : (K1, K2, K3, K4) -> V) -> ((K1, K2, K3, K4) -> V)

    memoize5

    fn[K1 : Hash + Eq, K2 : Hash + Eq, K3 : Hash + Eq, K4 : Hash + Eq, K5 : Hash + Eq, V] memoize5(f : (K1, K2, K3, K4, K5) -> V) -> ((K1, K2, K3, K4, K5) -> V)

    normal_fonts

    let normal_fonts : String

    preset

    let preset : String

    common CSS resets for Respo pages

    render_node

    fn[T, U] render_node(mount_target :
    Node
    , store : Ref[U], renderer : () ->
    RespoNode
    [T] raise
    RespoCommonError
    , dispatch_action : (T) -> Unit raise
    RespoCommonError
    , _interval : Float?) -> Unit raise
    RespoCommonError

    render elements

    show_obscure_state

    fn show_obscure_state(msg : String, v : ObscureState) -> Unit

    try_load_storage

    fn[Model :
    FromJson
    + Default] try_load_storage(key : String) -> Model

    ui_button

    let ui_button : String

    ui_button_danger

    let ui_button_danger : String

    ui_button_primary

    let ui_button_primary : String

    ui_center

    let ui_center : String

    layout items in column and center them with flexbox demos https://ui.respo-mvc.org/#/layouts.html

    ui_column

    let ui_column : String

    layout items in column and center them with flexbox demos https://ui.respo-mvc.org/#/layouts.html

    ui_column_dispersive

    let ui_column_dispersive : String

    layout items in column with flexbox, space around demos https://ui.respo-mvc.org/#/layouts.html

    ui_column_evenly

    let ui_column_evenly : String

    layout items in column with flexbox, space evenly demos https://ui.respo-mvc.org/#/layouts.html

    ui_column_parted

    let ui_column_parted : String

    layout items in column with flexbox, space between demos https://ui.respo-mvc.org/#/layouts.html

    ui_expand

    let ui_expand : String

    expand item with flex:1

    ui_font_code

    let ui_font_code : String

    monospace font for code, Source Code Pro, Menlo, Ubuntu Mono, Consolas

    ui_font_fancy

    let ui_font_fancy : String

    fancy font for title, Josefin Sans, Helvetica neue, Arial refers to https://fonts.google.com/specimen/Josefin+Sans or https://cdn.tiye.me/favored-fonts/main-fonts.css

    ui_font_normal

    let ui_font_normal : String

    normal font for text, Hind, Helvatica, Arial refers to https://fonts.google.com/specimen/Hind or https://cdn.tiye.me/favored-fonts/main-fonts.css

    ui_fullscreen

    let ui_fullscreen : String

    full page with absolute position

    ui_global

    let ui_global : String

    ui_input

    let ui_input : String

    let ui_link : String

    ui_row

    let ui_row : String

    layout items in row with flexbox, items are stretched demos https://ui.respo-mvc.org/#/layouts.html

    ui_row_center

    let ui_row_center : String

    layout items in row with flexbox, center them demos https://ui.respo-mvc.org/#/layouts.html

    ui_row_dispersive

    let ui_row_dispersive : String

    layout items in row with flexbox, space around demos https://ui.respo-mvc.org/#/layouts.html

    ui_row_evenly

    let ui_row_evenly : String

    layout items in row with flexbox, space evenly demos https://ui.respo-mvc.org/#/layouts.html

    ui_row_middle

    let ui_row_middle : String

    layout items in row with flexbox, space between demos https://ui.respo-mvc.org/#/layouts.html

    ui_row_parted

    let ui_row_parted : String

    layout items in row with flexbox, space between demos https://ui.respo-mvc.org/#/layouts.html

    ui_textarea

    let ui_textarea : String

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io