dioxus/README.md

188 lines
10 KiB
Markdown
Raw Normal View History

2021-01-16 15:31:17 +00:00
<div align="center">
<h1>🌗🚀 Dioxus</h1>
<p>
2021-03-02 06:47:27 +00:00
<strong>Frontend that scales.</strong>
2021-01-16 15:31:17 +00:00
</p>
</div>
2021-07-12 16:20:58 +00:00
<div align="center">
<!-- Crates version -->
2021-09-07 22:25:57 +00:00
<a href="https://crates.io/crates/dioxus">
<img src="https://img.shields.io/crates/v/dioxus.svg?style=flat-square"
2021-07-12 16:20:58 +00:00
alt="Crates.io version" />
</a>
<!-- Downloads -->
2021-09-07 22:25:57 +00:00
<a href="https://crates.io/crates/dioxus">
<img src="https://img.shields.io/crates/d/dioxus.svg?style=flat-square"
2021-07-12 16:20:58 +00:00
alt="Download" />
</a>
<!-- docs.rs docs -->
2021-09-07 22:25:57 +00:00
<a href="https://docs.rs/dioxus">
2021-07-12 16:20:58 +00:00
<img src="https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square"
alt="docs.rs docs" />
</a>
<!-- CI -->
2021-09-20 20:49:36 +00:00
<a href="https://github.com/jkelleyrtp/dioxus/actions">
<img src="https://github.com/jkelleyrtp/dioxus/workflows/CI/badge.svg"
2021-07-12 16:20:58 +00:00
alt="CI status" />
</a>
</div>
<div align="center">
<h3>
2021-09-07 22:25:57 +00:00
<a href="https://docs.rs/dioxus">
2021-07-12 16:20:58 +00:00
API Docs
</a>
<span> | </span>
2021-09-07 22:25:57 +00:00
<a href="https://docs.rs/dioxus">
2021-07-12 16:22:08 +00:00
Website
</a>
<span> | </span>
2021-09-07 22:25:57 +00:00
<a href="https://docs.rs/dioxus">
2021-07-12 16:22:08 +00:00
Examples
</a>
2021-07-12 16:20:58 +00:00
</h3>
</div>
<br/>
Dioxus is a portable, performant, and ergonomic framework for building cross-platform user experiences in Rust.
```rust
2021-12-01 03:48:05 +00:00
fn App(cx: Scope, props: &()) -> Element {
2021-07-08 16:01:31 +00:00
let mut count = use_state(cx, || 0);
2021-02-25 23:44:00 +00:00
2021-09-20 20:49:36 +00:00
cx.render(rsx!(
2021-07-11 23:31:07 +00:00
h1 { "High-Five counter: {count}" }
2021-07-08 16:01:31 +00:00
button { onclick: move |_| count += 1, "Up high!" }
button { onclick: move |_| count -= 1, "Down low!" }
2021-09-20 20:49:36 +00:00
))
};
```
2021-09-20 20:49:36 +00:00
Dioxus can be used to deliver webapps, desktop apps, static sites, liveview apps, mobile apps (WIP), and more. At its core, Dioxus is entirely renderer agnostic and has great documentation for creating new renderers for any platform.
If you know React, then you already know Dioxus.
### Unique features:
2021-10-19 16:09:23 +00:00
- Desktop apps running natively (no Electron!) in less than 10 lines of code.
2021-12-01 03:48:05 +00:00
- Incredibly ergonomic and powerful state management.
- Incredible inline documentation - hover and guides for all HTML elements, listeners, and events.
- Extremely memory efficient - 0 global allocations for steady-state components.
- Multithreaded asynchronous coroutine scheduler for first-class async support.
2021-07-12 16:19:50 +00:00
- And more! Read the full release post here.
2021-03-01 05:16:48 +00:00
## Get Started with...
2021-02-08 22:09:21 +00:00
<table style="width:100%" align="center">
<tr >
2021-03-29 16:31:47 +00:00
<th><a href="http://github.com/jkelleyrtp/dioxus">Web</a></th>
2021-02-08 22:08:26 +00:00
<th><a href="http://github.com/jkelleyrtp/dioxus">Desktop</a></th>
<th><a href="http://github.com/jkelleyrtp/dioxus">Mobile</a></th>
2021-06-15 14:02:46 +00:00
<th><a href="http://github.com/jkelleyrtp/dioxus">State</a></th>
2021-02-08 22:08:26 +00:00
<th><a href="http://github.com/jkelleyrtp/dioxus">Docs</a></th>
2021-02-08 22:09:21 +00:00
<th><a href="http://github.com/jkelleyrtp/dioxus">Tools</a></th>
2021-02-08 22:05:58 +00:00
<tr>
</table>
2021-09-07 22:32:47 +00:00
2021-09-20 20:49:36 +00:00
## Examples:
2021-10-14 16:47:56 +00:00
| File Navigator (Desktop) | Bluetooth scanner (Desktop) | TodoMVC (All platforms) | Widget Gallery |
| --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| [![asd](https://github.com/DioxusLabs/file-explorer-example/raw/master/image.png)](https://github.com/DioxusLabs/file-explorer-example) | ![asd](https://sixtyfps.io/resources/printerdemo_screenshot.png) | [![asd](https://github.com/DioxusLabs/todomvc/blob/master/example.png)](https://github.com/dioxusLabs/todomvc/) | ![asd](https://sixtyfps.io/resources/printerdemo_screenshot.png) |
2021-09-20 20:49:36 +00:00
2021-09-10 00:58:48 +00:00
See the awesome-dioxus page for a curated list of content in the Dioxus Ecosystem.
2021-12-01 03:48:05 +00:00
## Why Dioxus and why Rust?
2021-12-01 03:48:05 +00:00
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.
2021-12-01 03:48:05 +00:00
In contrast, Dioxus is written in Rust - which is almost like "TypeScript on steroids".
2021-12-01 03:48:05 +00:00
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 datastructures
- 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.
2021-06-24 15:09:38 +00:00
# Parity with React
2021-06-24 15:18:58 +00:00
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. This parity table does not necessarily include important ecosystem crates like code blocks, markdown, resizing hooks, etc.
2021-06-24 15:09:38 +00:00
2021-06-24 15:17:59 +00:00
2021-08-09 21:09:33 +00:00
| Feature | Dioxus | React | Notes for Dioxus |
| ------------------------- | ------ | ----- | -------------------------------------------------------------------- |
| Conditional Rendering | ✅ | ✅ | if/then to hide/show component |
| Map, Iterator | ✅ | ✅ | map/filter/reduce to produce rsx! |
| Keyed Components | ✅ | ✅ | advanced diffing with keys |
| Web | ✅ | ✅ | renderer for web browser |
| Desktop (webview) | ✅ | ✅ | renderer for desktop |
| Shared State (Context) | ✅ | ✅ | share state through the tree |
| Hooks | ✅ | ✅ | memory cells in components |
| SSR | ✅ | ✅ | render directly to string |
| Component Children | ✅ | ✅ | cx.children() as a list of nodes |
| Headless components | ✅ | ✅ | components that don't return real elements |
| Fragments | ✅ | ✅ | multiple elements without a real root |
| Manual Props | ✅ | ✅ | Manually pass in props with spread syntax |
| Controlled Inputs | ✅ | ✅ | stateful wrappers around inputs |
| CSS/Inline Styles | ✅ | ✅ | syntax for inline styles/attribute groups |
| Custom elements | ✅ | ✅ | Define new element primitives |
| Suspense | ✅ | ✅ | schedule future render from future/promise |
| Integrated error handling | ✅ | ✅ | Gracefully handle errors with ? syntax |
| NodeRef | ✅ | ✅ | gain direct access to nodes |
2021-08-09 21:09:33 +00:00
| Re-hydration | ✅ | ✅ | Pre-render to HTML to speed up first contentful paint |
| Jank-Free Rendering | ✅ | ✅ | Large diffs are segmented across frames for silky-smooth transitions |
| Effects | ✅ | ✅ | Run effects after a component has been committed to render |
| Cooperative Scheduling | 🛠 | ✅ | Prioritize important events over non-important events |
| Server Components | 🛠 | ✅ | Hybrid components for SPA and Server |
| Bundle Splitting | 👀 | ✅ | Efficiently and asynchronously load the app |
| Lazy Components | 👀 | ✅ | Dynamically load the new components as the page is loaded |
| 1st class global state | ✅ | ✅ | redux/recoil/mobx on top of context |
2021-08-09 21:09:33 +00:00
| Runs natively | ✅ | ❓ | runs as a portable binary w/o a runtime (Node) |
| Subtree Memoization | ✅ | ❓ | skip diffing static element subtrees |
| Compile-time correct | ✅ | ❓ | Throw errors on invalid template layouts |
| Heuristic Engine | ✅ | ❓ | track component memory usage to minimize future allocations |
| Fine-grained reactivity | 👀 | ❓ | Skip diffing for fine-grain updates |
2021-06-25 13:31:13 +00:00
2021-06-24 15:15:55 +00:00
- ✅ = implemented and working
- 🛠 = actively being worked on
2021-06-25 13:33:59 +00:00
- 👀 = not yet implemented or being worked on
2021-06-24 15:15:55 +00:00
- ❓ = not sure if will or can implement
2021-09-20 16:32:21 +00:00
2021-11-12 21:06:33 +00:00
2021-09-20 16:36:43 +00:00
## License
This project is licensed under the [MIT license].
[MIT license]: https://github.com/tokio-rs/tokio/blob/master/LICENSE
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in Pipette by you, shall be licensed as MIT, without any additional
terms or conditions.