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

44 lines
1 KiB
Rust
Raw Normal View History

2021-04-01 04:01:42 +00:00
use crate::recoil::*;
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));
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-05 01:47:53 +00:00
impl RecoilContext<()> {
pub fn add_todo(&self, contents: String) {}
2021-04-02 01:44:18 +00:00
2021-04-05 01:47:53 +00:00
pub fn remove_todo(&self, id: &uuid::Uuid) {
// TODOS.with().remove(id)
}
2021-04-02 01:44:18 +00:00
2021-04-05 01:47:53 +00:00
pub fn select_all_todos(&self) {}
2021-04-02 01:44:18 +00:00
2021-04-05 01:47:53 +00:00
pub fn toggle_todo(&self, id: &uuid::Uuid) {}
2021-04-02 01:44:18 +00:00
2021-04-05 01:47:53 +00:00
pub fn clear_completed(&self) {
// let (set, get) = (self.set, self.get);
2021-04-02 01:44:18 +00:00
2021-04-05 01:47:53 +00:00
// TOODS
// .get(&ctx)
// .iter()
// .filter(|(k, v)| v.checked)
// .map(|(k, v)| TODOS.remove(&ctx, k));
}
2021-04-02 01:44:18 +00:00
2021-04-05 01:47:53 +00:00
pub fn set_filter(&self, filter: &FilterState) {}
}