Merge branch 'master' into jk/documet-everything

This commit is contained in:
Jonathan Kelley committed 2022-02-26 17:33:06 -05:00
commit 77631bff1f
34 files changed
+891 -81

No files matched your search

+14 -11
View File
@@ -11,6 +11,7 @@ use std::{
future::Future,
pin::Pin,
rc::Rc,
sync::Arc,
};
/// for traceability, we use the raw fn pointer to identify the function
@@ -96,11 +97,10 @@ impl ScopeArena {
// Get the height of the scope
let height = parent_scope
.map(|id| self.get_scope(id).map(|scope| scope.height + 1))
.flatten()
.and_then(|id| self.get_scope(id).map(|scope| scope.height + 1))
.unwrap_or_default();
let parent_scope = parent_scope.map(|f| self.get_scope_raw(f)).flatten();
let parent_scope = parent_scope.and_then(|f| self.get_scope_raw(f));
/*
This scopearena aggressively reuses old scopes when possible.
@@ -582,12 +582,17 @@ impl ScopeState {
self.our_arena_idx
}
/// Get a handle to the raw update scheduler channel
pub fn scheduler_channel(&self) -> UnboundedSender<SchedulerMsg> {
self.tasks.sender.clone()
}
/// Create a subscription that schedules a future render for the reference component
///
/// ## Notice: you should prefer using prepare_update and get_scope_id
pub fn schedule_update(&self) -> Rc<dyn Fn() + 'static> {
pub fn schedule_update(&self) -> Arc<dyn Fn() + Send + Sync + 'static> {
let (chan, id) = (self.tasks.sender.clone(), self.scope_id());
Rc::new(move || {
Arc::new(move || {
let _ = chan.unbounded_send(SchedulerMsg::Immediate(id));
})
}
@@ -597,9 +602,9 @@ impl ScopeState {
/// A component's ScopeId can be obtained from `use_hook` or the [`ScopeState::scope_id`] method.
///
/// This method should be used when you want to schedule an update for a component
pub fn schedule_update_any(&self) -> Rc<dyn Fn(ScopeId)> {
pub fn schedule_update_any(&self) -> Arc<dyn Fn(ScopeId) + Send + Sync> {
let chan = self.tasks.sender.clone();
Rc::new(move |id| {
Arc::new(move |id| {
let _ = chan.unbounded_send(SchedulerMsg::Immediate(id));
})
}
@@ -656,8 +661,7 @@ impl ScopeState {
self.shared_contexts
.borrow_mut()
.insert(TypeId::of::<T>(), value.clone())
.map(|f| f.downcast::<T>().ok())
.flatten();
.and_then(|f| f.downcast::<T>().ok());
value
}
@@ -687,8 +691,7 @@ impl ScopeState {
self.shared_contexts
.borrow_mut()
.insert(TypeId::of::<T>(), value.clone())
.map(|f| f.downcast::<T>().ok())
.flatten();
.and_then(|f| f.downcast::<T>().ok());
return value;
}