No description
Find a file
Demonthos 047ed1e553
Subtree memorization / reactive templates (#488)
This commit adds subtree memoization to Dioxus.

Subtree memoization is basically a compile-time step that drastically 
reduces the amount of work the diffing engine needs to do at runtime by
extracting non-changing nodes out into a static "template." Templates 
are then understood by the various renderers in the ecosystem as a 
faster way of rendering the same items. 

For example, in the web, templates are simply a set of DOM Nodes created 
once and then cloned later. This is the same pattern frameworks like Lithtml
and SolidJS use to achieve near-perfect performance. 

Subtree memoization adds an additional level of complexity to Dioxus. The RSX
macro needs to be much smarter to identify changing/nonchanging nodes and
generate a mapping between the Template and its runtime counterparts.

This commit represents a working starter point for this work, adding support 
for templates for the web, desktop, liveview, ssr, and native-core renderers.
In the future we will try to shrink code generation, generally improve 
performance, and simplify our implementation.
2022-09-30 12:03:06 -07:00
.docker try fix 2022-02-06 23:27:24 +01:00
.github Fix propagation docs (#526) 2022-08-10 07:23:27 -05:00
.vscode Less clumsy configuration for desktop and mobile (#553) 2022-09-13 16:22:27 -07:00
docs Subtree memorization / reactive templates (#488) 2022-09-30 12:03:06 -07:00
examples feat: add an unhygenic render macro (#556) 2022-09-25 01:05:16 -07:00
notes feat: add an unhygenic render macro (#556) 2022-09-25 01:05:16 -07:00
packages Subtree memorization / reactive templates (#488) 2022-09-30 12:03:06 -07:00
translations/pt-br Add PT-BR translations (#456) 2022-07-11 13:28:12 -04:00
.gitignore active_class prop for Router 2022-03-13 16:35:28 +00:00
Cargo.toml Subtree memorization / reactive templates (#488) 2022-09-30 12:03:06 -07:00
CHANGELOG.md feat: add changelogs 2022-01-29 10:17:14 -05:00
codecov.yml ci: no more codecov failing 2022-02-13 12:44:17 -05:00
LICENSE-APACHE Add actual copies of the relevant licenses 2022-01-30 11:50:57 -06:00
LICENSE-MIT Add actual copies of the relevant licenses 2022-01-30 11:50:57 -06:00
Makefile.toml Exclude benchmarks from testing (#492) 2022-07-07 09:59:00 -04:00
README.md Document formatting and typo fixes (#495) 2022-09-05 13:58:19 -05:00

Dioxus


Dioxus is a portable, performant, and ergonomic framework for building cross-platform user interfaces in Rust.

fn app(cx: Scope) -> Element {
    let mut count = use_state(&cx, || 0);

    cx.render(rsx! {
        h1 { "High-Five counter: {count}" }
        button { onclick: move |_| count += 1, "Up high!" }
        button { onclick: move |_| count -= 1, "Down low!" }
    })
}

Dioxus can be used to deliver webapps, desktop apps, static sites, mobile apps, TUI apps, liveview apps, and more. Dioxus is entirely renderer agnostic and can be used as platform for any renderer.

If you know React, then you already know Dioxus.

Unique features:

  • Desktop apps running natively (no Electron!) in less than 10 lines of code.
  • Incredibly ergonomic and powerful state management.
  • Comprehensive inline documentation - hover and guides for all HTML elements, listeners, and events.
  • Extremely memory efficient - 0 global allocations for steady-state components.
  • Multi-channel asynchronous scheduler for first-class async support.
  • And more! Read the full release post.

Get Started with...

Tutorial Web Desktop SSR Mobile

Example Projects:

File Navigator (Desktop) WiFi scanner (Desktop) TodoMVC (All platforms) E-commerce w/ Tailwind (SSR/LiveView)
File Explorer Wifi Scanner Demo TodoMVC example E-commerce Example

See the awesome-dioxus page for a curated list of content in the Dioxus Ecosystem.

Why Dioxus and why Rust?

TypeScript is a fantastic addition to JavaScript, but it's still fundamentally JavaScript. TS code runs slightly slower, has tons of configuration options, and not every package is properly typed.

By using Rust, we gain:

  • Static types for every library
  • Immutability by default
  • A simple and intuitive module system
  • Integrated documentation (go to source actually goes to source)
  • Advanced pattern matching
  • Clean, efficient, composable iterators
  • Inline built-in unit/integration testing
  • Best-in-class error handling
  • Powerful and sane standard library
  • Flexible macro system
  • Access to crates.io

Specifically, Dioxus provides us many other assurances:

  • Proper use of immutable data structures
  • Guaranteed error handling (so you can sleep easy at night not worrying about cannot read property of undefined)
  • Native performance on mobile
  • Direct access to system IO

And much more. Dioxus makes Rust apps just as fast to write as React apps, but affords more robustness, giving your frontend team greater confidence in making big changes in shorter time.

Why NOT Dioxus?

You shouldn't use Dioxus if:

  • You don't like the React Hooks approach to frontend
  • You need a no-std renderer
  • You want to support browsers where Wasm or asm.js are not supported.
  • You need a Send+Sync UI solution (Dioxus is not currently thread-safe)

Comparison with other Rust UI frameworks

Dioxus primarily emphasizes developer experience and familiarity with React principles.

  • Yew: prefers the elm pattern instead, no borrowed props, supports SSR (no hydration), no direct desktop/mobile support.
  • Percy: Supports SSR but with less emphasis on state management and event handling.
  • Sycamore: VDOM-less using fine-grained reactivity, but no direct support for desktop/mobile.
  • Dominator: Signal-based zero-cost alternative, less emphasis on community and docs.
  • Azul: Fully native HTML/CSS renderer for desktop applications, no support for web/ssr

Parity with React & Roadmap

Dioxus is heavily inspired by React, but we want your transition to feel like an upgrade. Dioxus is most of the way there, but missing a few key features. These include:

  • Portals
  • Suspense integration with SSR
  • Server Components / Bundle Splitting / Lazy

Dioxus is unique in the Rust ecosystem in that it supports:

  • Components with props that borrow from their parent
  • Server-side-rendering with client-side hydration
  • Support for desktop applications

For more information on what features are currently available and the roadmap for the future, be sure to check out the guide.

Projects in the ecosystem

Want to jump in and help build the future of Rust frontend? There's plenty of places where your contributions can make a huge difference:

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Dioxus by you, shall be licensed as MIT, without any additional terms or conditions.