state.rs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. use crate::recoil::*;
  2. pub static TODOS: AtomFamily<uuid::Uuid, TodoItem> = atom_family(|_| {});
  3. pub static FILTER: Atom<FilterState> = atom(|_| FilterState::All);
  4. pub static SHOW_ALL_TODOS: selector<bool> = selector(|g| g.getter(|f| false));
  5. #[derive(PartialEq)]
  6. pub enum FilterState {
  7. All,
  8. Active,
  9. Completed,
  10. }
  11. #[derive(Debug, PartialEq, Clone)]
  12. pub struct TodoItem {
  13. pub id: uuid::Uuid,
  14. pub checked: bool,
  15. pub contents: String,
  16. }
  17. impl RecoilContext<()> {
  18. pub fn add_todo(&self, contents: String) {}
  19. pub fn remove_todo(&self, id: &uuid::Uuid) {
  20. // TODOS.with().remove(id)
  21. }
  22. pub fn select_all_todos(&self) {}
  23. pub fn toggle_todo(&self, id: &uuid::Uuid) {}
  24. pub fn clear_completed(&self) {
  25. // let (set, get) = (self.set, self.get);
  26. // TOODS
  27. // .get(&cx)
  28. // .iter()
  29. // .filter(|(k, v)| v.checked)
  30. // .map(|(k, v)| TODOS.remove(&cx, k));
  31. }
  32. pub fn set_filter(&self, filter: &FilterState) {}
  33. }