|
@@ -1,4 +1,3 @@
|
|
|
-
|
|
|
<div align="center">
|
|
|
<h1>Fermi ⚛</h1>
|
|
|
<p>
|
|
@@ -6,7 +5,6 @@
|
|
|
</p>
|
|
|
</div>
|
|
|
|
|
|
-
|
|
|
<div align="center">
|
|
|
<!-- Crates version -->
|
|
|
<a href="https://crates.io/crates/dioxus">
|
|
@@ -30,21 +28,21 @@
|
|
|
</a>
|
|
|
</div>
|
|
|
|
|
|
------
|
|
|
+---
|
|
|
|
|
|
Fermi is a global state management solution for Dioxus that's as easy as `use_state`.
|
|
|
|
|
|
Inspired by atom-based state management solutions, all state in Fermi starts as an `atom`:
|
|
|
|
|
|
```rust, ignore
|
|
|
-static NAME: Atom<&str> = |_| "Dioxus";
|
|
|
+static NAME: Atom<&str> = Atom(|_| "Dioxus");
|
|
|
```
|
|
|
|
|
|
From anywhere in our app, we can read the value of our atom:
|
|
|
|
|
|
-```rust, ignores
|
|
|
+```rust, ignore
|
|
|
fn NameCard(cx: Scope) -> Element {
|
|
|
- let name = use_read(cx, NAME);
|
|
|
+ let name = use_read(cx, &NAME);
|
|
|
cx.render(rsx!{ h1 { "Hello, {name}"} })
|
|
|
}
|
|
|
```
|
|
@@ -53,7 +51,7 @@ We can also set the value of our atom, also from anywhere in our app:
|
|
|
|
|
|
```rust, ignore
|
|
|
fn NameCard(cx: Scope) -> Element {
|
|
|
- let set_name = use_set(cx, NAME);
|
|
|
+ let set_name = use_set(cx, &NAME);
|
|
|
cx.render(rsx!{
|
|
|
button {
|
|
|
onclick: move |_| set_name("Fermi"),
|
|
@@ -66,10 +64,10 @@ fn NameCard(cx: Scope) -> Element {
|
|
|
If needed, we can update the atom's value, based on itself:
|
|
|
|
|
|
```rust, ignore
|
|
|
-static COUNT: Atom<i32> = |_| 0;
|
|
|
+static COUNT: Atom<i32> = Atom(|_| 0);
|
|
|
|
|
|
fn Counter(cx: Scope) -> Element {
|
|
|
- let mut count = use_atom_state(cx, COUNT);
|
|
|
+ let mut count = use_atom_state(cx, &COUNT);
|
|
|
|
|
|
cx.render(rsx!{
|
|
|
p {
|
|
@@ -86,6 +84,7 @@ fn Counter(cx: Scope) -> Element {
|
|
|
It's that simple!
|
|
|
|
|
|
## Installation
|
|
|
+
|
|
|
Fermi is currently under construction, so you have to use the `master` branch to get started.
|
|
|
|
|
|
```toml
|
|
@@ -93,10 +92,10 @@ Fermi is currently under construction, so you have to use the `master` branch to
|
|
|
fermi = { git = "https://github.com/dioxuslabs/dioxus" }
|
|
|
```
|
|
|
|
|
|
-
|
|
|
## Running examples
|
|
|
|
|
|
The examples here use Dioxus Desktop to showcase their functionality. To run an example, use
|
|
|
+
|
|
|
```sh
|
|
|
$ cargo run --example fermi
|
|
|
```
|
|
@@ -104,6 +103,7 @@ $ cargo run --example fermi
|
|
|
## Features
|
|
|
|
|
|
Broadly our feature set required to be released includes:
|
|
|
+
|
|
|
- [x] Support for Atoms
|
|
|
- [x] Support for AtomRef (for values that aren't `Clone`)
|
|
|
- [ ] Support for Atom Families
|