From 2dd40ec202c0005a62fec2c6fedf032a682f6cee Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Thu, 2 Mar 2023 12:02:12 -0600 Subject: [PATCH] add docs to remaining items --- packages/hooks/src/use_shared_state.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/hooks/src/use_shared_state.rs b/packages/hooks/src/use_shared_state.rs index a7afc619e..eb836a211 100644 --- a/packages/hooks/src/use_shared_state.rs +++ b/packages/hooks/src/use_shared_state.rs @@ -102,6 +102,7 @@ pub fn use_shared_state(cx: &ScopeState) -> Option<&UseSharedState { state: UseSharedState, scope_id: ScopeId, @@ -115,15 +116,18 @@ impl Drop for UseSharedStateOwner { } } +/// State that is shared between components through the context system pub struct UseSharedState { pub(crate) inner: Rc>>, } impl UseSharedState { + /// Notify all consumers of the state that it has changed. (This is called automatically when you call "write") pub fn notify_consumers(&self) { self.inner.borrow_mut().notify_consumers(); } + /// Read the shared value pub fn read(&self) -> Ref<'_, T> { Ref::map(self.inner.borrow(), |inner| &inner.value) } @@ -131,7 +135,7 @@ impl UseSharedState { /// Calling "write" will force the component to re-render /// /// - /// TODO: We prevent unncessary notifications only in the hook, but we should figure out some more global lock + // TODO: We prevent unncessary notifications only in the hook, but we should figure out some more global lock pub fn write(&self) -> RefMut<'_, T> { let mut value = self.inner.borrow_mut(); value.notify_consumers();