// ======================== // Important hooks // ======================== pub fn init_recoil_root(ctx: Context) { let res = ctx.try_use_context::(); ctx.create_context(move || { // if res.is_ok() { panic!( "Cannot initialize a recoil root inside of a recoil root.\n An app may only have one recoil root per virtual dom instance" ); } RecoilRoot {} }) } pub fn use_atom<'a, T: PartialEq>(c: Context<'a>, t: &'static Atom) -> &'a T { todo!() } pub fn use_set_atom<'a, T: PartialEq>(c: Context<'a>, t: &'static Atom) -> Rc { todo!() } use std::rc::Rc; use dioxus_core::virtual_dom::Context; pub struct RecoilRoot {} pub struct RecoilContext {} impl RecoilContext { /// Get the value of an atom. Returns a reference to the underlying data. pub fn get(&self, t: &'static Atom) -> &T { todo!() } /// Replace an existing value with a new value /// /// This does not replace the value instantly. /// All calls to "get" will return the old value until the component is rendered. pub fn set(&self, t: &'static Atom, new: T) { self.modify(t, move |old| *old = new); } /// Modify lets you modify the value in place. However, because there's no previous value around to compare /// the new one with, we are unable to memoize the change. As such, all downsteam users of this Atom will /// be updated, causing all subsrcibed components to re-render. /// /// This is fine for most values, but might not be performant when dealing with collections. For collections, /// use the "Family" variants as these will stay memoized for inserts, removals, and modifications. /// /// Note - like "set" this won't propogate instantly. Once all "gets" are dropped, only then will the update occur pub fn modify(&self, t: &'static Atom, f: impl FnOnce(&mut T) -> O) -> O { todo!() } } pub fn use_recoil_context(c: Context) -> &T { todo!() } // pub fn use_callback<'a>(c: &Context<'a>, f: impl Fn() -> G) -> &'a RecoilContext { // todo!() // } pub trait Readable {} impl Readable for &'static Atom {} impl Readable for &'static AtomFamily {} pub fn use_atom_family<'a, K: PartialEq, V: PartialEq>( c: &Context<'a>, t: &'static AtomFamily, g: K, ) -> &'a V { todo!() } pub struct AtomBuilder { pub key: String, pub manual_init: Option T>>, _never: std::marker::PhantomData, } impl AtomBuilder { pub fn new() -> Self { Self { key: "".to_string(), manual_init: None, _never: std::marker::PhantomData {}, } } pub fn init T + 'static>(&mut self, f: A) { self.manual_init = Some(Box::new(f)); } pub fn set_key(&mut self, _key: &'static str) {} } // ===================================== // Atom // ===================================== pub struct atom(pub fn(&mut AtomBuilder) -> T); pub type Atom = atom; // ===================================== // Atom Family // ===================================== pub struct AtomFamilyBuilder { _never: std::marker::PhantomData<(K, V)>, } pub struct atom_family(pub fn(&mut AtomFamilyBuilder)); pub type AtomFamily = atom_family; // ===================================== // Selectors // ===================================== pub struct SelectorApi {} impl SelectorApi { pub fn get(&self, t: &'static Atom) -> &T { todo!() } } // pub struct SelectorBuilder { // _p: std::marker::PhantomData, // } // impl SelectorBuilder { // pub fn getter(self, f: impl Fn(()) -> O) -> SelectorBuilder { // todo!() // // std::rc::Rc::pin(value) // // todo!() // } // } pub struct selector(pub fn(&SelectorApi) -> O); // pub struct selector(pub fn(SelectorBuilder) -> SelectorBuilder); pub type Selector = selector; pub fn use_selector<'a, O>(c: Context<'a>, s: &'static Selector) -> &'a O { todo!() } pub fn callback_example(ctx: Context) { let set_user = use_recoil_callback(ctx, |api| { |a: String, b: ()| { // } }); let set_user = use_recoil_callback(ctx, |api| { // }); } fn use_recoil_callback(ctx: Context, f: impl Fn(RecoilContext) -> F) -> F { todo!() } mod analyzer { use super::*; const TITLE: Atom<&'static str> = atom(|_| Default::default()); // pub fn use_add_todo(ctx: Context) -> impl Fn(&'static str) + '_ { // use_recoil_callback(ctx, move |api| move |a: &'static str| api.set(&TITLE, a)) // } struct Analyzer(RecoilContext); fn use_analyzer(ctx: Context) -> Analyzer { use_recoil_callback(ctx, |api| Analyzer(api)) } }