wip: rename fc to component
This commit is contained in:
1 parent
85ab8b91c6
commit
1e4a599d14
61 files changed
+524
-145
No files matched your search
@@ -8,7 +8,7 @@ use std::{
|
||||
type ProvidedState<T> = RefCell<ProvidedStateInner<T>>;
|
||||
|
||||
// Tracks all the subscribers to a shared State
|
||||
pub(crate) struct ProvidedStateInner<T> {
|
||||
pub struct ProvidedStateInner<T> {
|
||||
value: Rc<RefCell<T>>,
|
||||
notify_any: Rc<dyn Fn(ScopeId)>,
|
||||
consumers: HashSet<ScopeId>,
|
||||
@@ -20,6 +20,14 @@ impl<T> ProvidedStateInner<T> {
|
||||
(self.notify_any)(*consumer);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write(&self) -> RefMut<T> {
|
||||
self.value.borrow_mut()
|
||||
}
|
||||
|
||||
pub fn read(&self) -> Ref<T> {
|
||||
self.value.borrow()
|
||||
}
|
||||
}
|
||||
|
||||
/// This hook provides some relatively light ergonomics around shared state.
|
||||
@@ -114,10 +122,10 @@ impl<'a, T: 'static> UseSharedState<'a, T> {
|
||||
}
|
||||
|
||||
pub fn notify_consumers(self) {
|
||||
// if !self.needs_notification.get() {
|
||||
self.root.borrow_mut().notify_consumers();
|
||||
// self.needs_notification.set(true);
|
||||
// }
|
||||
if !self.needs_notification.get() {
|
||||
self.root.borrow_mut().notify_consumers();
|
||||
self.needs_notification.set(true);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_write(&self) -> (Ref<'_, T>, &Self) {
|
||||
@@ -138,6 +146,10 @@ impl<'a, T: 'static> UseSharedState<'a, T> {
|
||||
pub fn write_silent(&self) -> RefMut<'_, T> {
|
||||
self.value.borrow_mut()
|
||||
}
|
||||
|
||||
pub fn inner(&self) -> Rc<RefCell<ProvidedStateInner<T>>> {
|
||||
self.root.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Copy for UseSharedState<'_, T> {}
|
||||
|
||||
Reference in new issue
Block a user