dioxus/packages/web/examples/todomvc/state.rs

52 lines
1.2 KiB
Rust
Raw Normal View History

2021-04-01 04:01:42 +00:00
use crate::recoil::*;
2021-04-02 01:44:18 +00:00
use dioxus_core::prelude::Context;
2021-04-01 04:01:42 +00:00
pub static TODOS: AtomFamily<uuid::Uuid, TodoItem> = atom_family(|_| {});
pub static FILTER: Atom<FilterState> = atom(|_| FilterState::All);
2021-04-02 01:44:18 +00:00
pub static SHOW_ALL_TODOS: selector<bool> = selector(|g| g.getter(|f| false));
// an atomfamily is just a HashMap<K, Pin<Rc<V>>> that pins the Rc and exposes the values by reference
// we could do a more advanced management, but this is fine too
2021-04-01 04:01:42 +00:00
#[derive(PartialEq)]
pub enum FilterState {
All,
Active,
Completed,
}
#[derive(Debug, PartialEq, Clone)]
pub struct TodoItem {
pub id: uuid::Uuid,
pub checked: bool,
pub contents: String,
}
2021-04-02 01:44:18 +00:00
pub fn add_todo(ctx: &Context, contents: String) {}
pub fn remove_todo(ctx: &Context, id: &uuid::Uuid) {
TODOS.with(&ctx).remove(id)
}
pub fn select_all_todos(ctx: &Context) {}
pub fn toggle_todo(ctx: &Context, id: &uuid::Uuid) {}
pub fn clear_completed(ctx: &Context) {
let (set, get) = (self.set, self.get);
TOODS
.get(&ctx)
.iter()
.filter(|(k, v)| v.checked)
.map(|(k, v)| TODOS.remove(&ctx, k));
2021-04-01 04:01:42 +00:00
}
2021-04-02 01:44:18 +00:00
pub fn set_filter(ctx: &Context, filter: &FilterState) {}
struct TodoManager<'a> {}
fn use_todos(ctx: &Context) {}
#[test]
fn test() {}