add simple suspense methods

This commit is contained in:
Jonathan Kelley committed 2023-07-14 16:56:17 -07:00
1 parent cbd88bbcc3
commit 81075748f6
11 files changed
+52 -189

No files matched your search

-2
View File
@@ -1,11 +1,9 @@
use crate::ScopeId;
use slab::Slab;
mod suspense;
mod task;
mod wait;
pub use suspense::*;
pub use task::*;
/// The type of message that can be sent to the scheduler.
+5 -11
View File
@@ -11,17 +11,10 @@ use std::{
collections::HashSet,
};
/// An ID representing an ongoing suspended component
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub(crate) struct SuspenseId(pub usize);
/// A boundary in the VirtualDom that captures all suspended components below it
pub struct SuspenseContext {
pub(crate) id: ScopeId,
pub(crate) waiting_on: RefCell<HashSet<SuspenseId>>,
pub(crate) mutations: RefCell<Mutations<'static>>,
pub(crate) placeholder: Cell<Option<ElementId>>,
pub(crate) created_on_stack: Cell<usize>,
pub(crate) waiting_on: RefCell<HashSet<ScopeId>>,
}
impl SuspenseContext {
@@ -30,9 +23,10 @@ impl SuspenseContext {
Self {
id,
waiting_on: Default::default(),
mutations: RefCell::new(Mutations::default()),
placeholder: Cell::new(None),
created_on_stack: Cell::new(0),
}
}
pub fn mark_suspend(&self, id: ScopeId) {
self.waiting_on.borrow_mut().insert(id);
}
}
+2 -8
View File
@@ -1,5 +1,5 @@
use crate::{innerlude::SuspenseContext, ScopeId, TaskId, VirtualDom};
use std::{rc::Rc, task::Context};
use crate::{TaskId, VirtualDom};
use std::task::Context;
impl VirtualDom {
/// Handle notifications by tasks inside the scheduler
@@ -27,10 +27,4 @@ impl VirtualDom {
tasks.try_remove(id.0);
}
}
pub(crate) fn acquire_suspense_boundary(&self, id: ScopeId) -> Rc<SuspenseContext> {
self.scopes[id]
.consume_context::<Rc<SuspenseContext>>()
.unwrap()
}
}