#dom #ui #react #gui #ui-framework #ui-elements

dioxus-core

为 Dioxus 提供核心功能 - 一个无渲染器依赖的并发型虚拟DOM,用于交互式用户体验

28 个版本

0.6.0-alpha.22024年8月7日
0.5.6 2024年7月18日
0.5.0 2024年3月28日
0.4.3 2023年12月7日
0.1.2 2021年2月28日

#1974Web编程

Download history 5259/week @ 2024-05-01 4912/week @ 2024-05-08 5200/week @ 2024-05-15 4884/week @ 2024-05-22 5159/week @ 2024-05-29 4806/week @ 2024-06-05 4922/week @ 2024-06-12 5125/week @ 2024-06-19 4640/week @ 2024-06-26 2678/week @ 2024-07-03 3433/week @ 2024-07-10 4708/week @ 2024-07-17 4647/week @ 2024-07-24 4818/week @ 2024-07-31 4529/week @ 2024-08-07 4040/week @ 2024-08-14

18,899 每月下载量
132 个包中使用 (直接使用 34 个)

MIT/Apache

420KB
8K SLoC

dioxus-core

dioxus-core 为 Rust 提供了一个快速且功能丰富的 VirtualDom 实现。

# tokio::runtime::Runtime::new().unwrap().block_on(async {
use dioxus_core::prelude::*;
use dioxus_core::*;

let mut vdom = VirtualDom::new(app);
let real_dom = SomeRenderer::new();

loop {
    tokio::select! {
        evt = real_dom.event() => vdom.handle_event("onclick", evt, ElementId(0), true),
        _ = vdom.wait_for_work() => {}
    }
    vdom.render_immediate(&mut real_dom.apply())
}

# fn app() -> Element { VNode::empty() }
# struct SomeRenderer; impl SomeRenderer { fn new() -> SomeRenderer { SomeRenderer } async fn event(&self) -> std::rc::Rc<dyn std::any::Any> { unimplemented!() } fn apply(&self) -> Mutations { Mutations::default() } }
# });

功能

虚拟DOM是一个高效且灵活的树形数据结构,允许您管理图形用户界面的状态。Dioxus 虚拟DOM可能是 Rust 中功能最全面的虚拟DOM实现,支持在 Web、桌面、移动、SSR、TUI、LiveView 等多个渲染器中使用。当您使用 Dioxus 虚拟DOM时,您可以立即让您的渲染器用户利用 Dioxus 组件、钩子和相关工具的广泛生态系统。

dioxus-core 的某些功能包括

  • UI组件只是函数
  • 状态由钩子提供
  • 深度集成异步
  • 强性能关注
  • 集成热重载支持
  • 可扩展的UI元素及其属性系统

如果您是初学者,请首先查看指南。

理解实现

dioxus-core 被设计成轻量级的包,它暴露了多个灵活的原始结构,而不深入关注状态管理的复杂性。我们在 dioxus-hooks 包以及 dioxus-signals 包中基于这些原始结构提供了一些有用的抽象。

需要理解的重要抽象包括

用法

dioxus 包导出 rsx 宏,该宏将 Rust 的简洁语法转换为有用的形式。

首先,从您的应用程序开始

# use dioxus::dioxus_core::Mutations;
use dioxus::prelude::*;

// First, declare a root component
fn app() -> Element {
    rsx!{
        div { "hello world" }
    }
}

fn main() {
    // Next, create a new VirtualDom using this app as the root component.
    let mut dom = VirtualDom::new(app);

    // The initial render of the dom will generate a stream of edits for the real dom to apply
    let mutations = dom.rebuild_to_vec();
}

贡献

许可证

本项目采用MIT许可证

除非您明确指出,否则您提交给Dioxus的任何有意贡献都应按MIT许可证授权,不附加任何额外条款或条件。

依赖项

~2.4–8.5MB
~66K SLoC