feat: split apart template mutations

This commit is contained in:
Jonathan Kelley committed 2022-11-08 19:39:37 -08:00
1 parent 203935834d
commit fc9fe6e560
21 files changed
+431 -222

No files matched your search

+17 -13
View File
@@ -19,23 +19,14 @@ use crate::{
TaskId,
};
pub struct Scope<'a, T = ()> {
pub type Scope<'a, T = ()> = &'a Scoped<'a, T>;
pub struct Scoped<'a, T = ()> {
pub scope: &'a ScopeState,
pub props: &'a T,
}
impl<T> Copy for Scope<'_, T> {}
impl<T> Clone for Scope<'_, T> {
fn clone(&self) -> Self {
Self {
props: self.props,
scope: self.scope,
}
}
}
impl<'a, T> std::ops::Deref for Scope<'a, T> {
impl<'a, T> std::ops::Deref for Scoped<'a, T> {
type Target = &'a ScopeState;
fn deref(&self) -> &Self::Target {
@@ -298,6 +289,19 @@ impl ScopeState {
}
}
/// Return any context of type T if it exists on this scope
pub fn has_context<T: 'static + Clone>(&self) -> Option<T> {
match self.shared_contexts.borrow().get(&TypeId::of::<T>()) {
Some(shared) => Some(
(*shared
.downcast_ref::<T>()
.expect("Context of type T should exist"))
.clone(),
),
None => None,
}
}
/// Pushes the future onto the poll queue to be polled after the component renders.
pub fn push_future(&self, fut: impl Future<Output = ()> + 'static) -> TaskId {
self.tasks.spawn(self.id, fut)