From 366a0a8026f98e5fc61a52a26db05d278bb651a4 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Wed, 20 Apr 2022 09:45:34 -0400 Subject: [PATCH] feat: read works on fermi root --- packages/fermi/src/root.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/fermi/src/root.rs b/packages/fermi/src/root.rs index d3f10afa9..c7c234ddb 100644 --- a/packages/fermi/src/root.rs +++ b/packages/fermi/src/root.rs @@ -95,7 +95,22 @@ impl AtomRoot { } } - pub fn read(&self, _f: impl Readable) -> &V { - todo!() + pub fn read(&self, f: impl Readable) -> Rc { + let mut atoms = self.atoms.borrow_mut(); + + // initialize the value if it's not already initialized + if let Some(slot) = atoms.get_mut(&f.unique_id()) { + slot.value.clone().downcast().unwrap() + } else { + let value = Rc::new(f.init()); + atoms.insert( + f.unique_id(), + Slot { + value: value.clone(), + subscribers: HashSet::new(), + }, + ); + value + } } }