feat: split apart template mutations
This commit is contained in:
1 parent
203935834d
commit
fc9fe6e560
21 files changed
+431
-222
No files matched your search
@@ -6,7 +6,10 @@ use std::{
|
||||
};
|
||||
|
||||
use super::{waker::RcWake, SchedulerMsg};
|
||||
use crate::{innerlude::Mutation, Element, ScopeId};
|
||||
use crate::{
|
||||
innerlude::{Mutation, Renderer},
|
||||
Element, ScopeId,
|
||||
};
|
||||
use futures_task::Waker;
|
||||
use futures_util::Future;
|
||||
|
||||
@@ -14,27 +17,27 @@ use futures_util::Future;
|
||||
pub struct SuspenseId(pub usize);
|
||||
|
||||
pub type SuspenseContext = Rc<RefCell<SuspenseBoundary>>;
|
||||
|
||||
/// Essentially a fiber in React
|
||||
pub struct SuspenseBoundary {
|
||||
pub id: ScopeId,
|
||||
pub waiting_on: HashSet<SuspenseId>,
|
||||
pub mutations: Vec<Mutation<'static>>,
|
||||
pub mutations: Renderer<'static>,
|
||||
}
|
||||
|
||||
impl SuspenseBoundary {
|
||||
pub fn new(id: ScopeId) -> Self {
|
||||
Self {
|
||||
pub fn new(id: ScopeId) -> Rc<RefCell<Self>> {
|
||||
Rc::new(RefCell::new(Self {
|
||||
id,
|
||||
waiting_on: Default::default(),
|
||||
mutations: Default::default(),
|
||||
}
|
||||
mutations: Renderer::new(0),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SuspenseLeaf {
|
||||
pub id: SuspenseId,
|
||||
pub scope_id: ScopeId,
|
||||
pub boundary: ScopeId,
|
||||
pub tx: futures_channel::mpsc::UnboundedSender<SchedulerMsg>,
|
||||
pub notified: Cell<bool>,
|
||||
|
||||
@@ -43,10 +46,10 @@ pub struct SuspenseLeaf {
|
||||
|
||||
impl RcWake for SuspenseLeaf {
|
||||
fn wake_by_ref(arc_self: &Rc<Self>) {
|
||||
if arc_self.notified.get() {
|
||||
return;
|
||||
}
|
||||
arc_self.notified.set(true);
|
||||
// if arc_self.notified.get() {
|
||||
// return;
|
||||
// }
|
||||
// arc_self.notified.set(true);
|
||||
_ = arc_self
|
||||
.tx
|
||||
.unbounded_send(SchedulerMsg::SuspenseNotified(arc_self.id));
|
||||
|
||||
@@ -3,7 +3,7 @@ use futures_util::{FutureExt, StreamExt};
|
||||
|
||||
use crate::{
|
||||
factory::RenderReturn,
|
||||
innerlude::{Mutation, SuspenseContext},
|
||||
innerlude::{Mutation, Renderer, SuspenseContext},
|
||||
VNode, VirtualDom,
|
||||
};
|
||||
|
||||
@@ -38,6 +38,8 @@ impl VirtualDom {
|
||||
}
|
||||
|
||||
SchedulerMsg::SuspenseNotified(id) => {
|
||||
println!("suspense notified");
|
||||
|
||||
let leaf = self
|
||||
.scheduler
|
||||
.handle
|
||||
@@ -63,11 +65,19 @@ impl VirtualDom {
|
||||
// continue rendering the tree until we hit yet another suspended component
|
||||
if let futures_task::Poll::Ready(new_nodes) = as_pinned_mut.poll_unpin(&mut cx)
|
||||
{
|
||||
let boundary = &self.scopes[leaf.boundary.0]
|
||||
let boundary = &self.scopes[leaf.scope_id.0]
|
||||
.consume_context::<SuspenseContext>()
|
||||
.unwrap();
|
||||
|
||||
println!("ready pool");
|
||||
|
||||
let mut fiber = boundary.borrow_mut();
|
||||
|
||||
println!(
|
||||
"Existing mutations {:?}, scope {:?}",
|
||||
fiber.mutations, fiber.id
|
||||
);
|
||||
|
||||
let scope = &mut self.scopes[scope_id.0];
|
||||
let arena = scope.current_arena();
|
||||
|
||||
@@ -77,18 +87,24 @@ impl VirtualDom {
|
||||
if let RenderReturn::Sync(Some(template)) = ret {
|
||||
let mutations = &mut fiber.mutations;
|
||||
let template: &VNode = unsafe { std::mem::transmute(template) };
|
||||
let mutations: &mut Vec<Mutation> =
|
||||
let mutations: &mut Renderer =
|
||||
unsafe { std::mem::transmute(mutations) };
|
||||
|
||||
self.scope_stack.push(scope_id);
|
||||
self.create(mutations, template);
|
||||
self.scope_stack.pop();
|
||||
|
||||
println!("{:?}", mutations);
|
||||
println!("{:#?}", mutations);
|
||||
} else {
|
||||
println!("nodes arent right");
|
||||
}
|
||||
} else {
|
||||
println!("not ready");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// now proces any events. If we end up running a component and it generates mutations, then we should run those mutations
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user