-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create VirtualDom struct and reorganize
- Loading branch information
Showing
15 changed files
with
230 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use crate::Tree; | ||
use slotmap::{DefaultKey, SlotMap}; | ||
use std::{ | ||
any::{Any, TypeId}, | ||
cell::RefCell, | ||
collections::{HashMap, VecDeque}, | ||
rc::Rc, | ||
task::Waker, | ||
time::Instant, | ||
}; | ||
|
||
#[derive(Default)] | ||
pub(crate) struct ScopeInner { | ||
pub(crate) contexts: HashMap<TypeId, Rc<dyn Any>>, | ||
pub(crate) hooks: Vec<Rc<dyn Any>>, | ||
pub(crate) hook_idx: usize, | ||
pub(crate) droppers: Vec<Box<dyn FnMut()>>, | ||
} | ||
|
||
#[derive(Clone, Default)] | ||
pub(crate) struct Scope { | ||
pub(crate) inner: Rc<RefCell<ScopeInner>>, | ||
} | ||
|
||
#[derive(Default)] | ||
pub(crate) struct RuntimeInner { | ||
pub(crate) node: Option<DefaultKey>, | ||
pub(crate) pending: VecDeque<DefaultKey>, | ||
pub(crate) scope: Option<Scope>, | ||
pub(crate) nodes: SlotMap<DefaultKey, *mut dyn Tree>, | ||
pub(crate) waker: Option<Waker>, | ||
pub(crate) contexts: HashMap<TypeId, Rc<dyn Any>>, | ||
pub(crate) limit: Option<Instant>, | ||
} | ||
|
||
#[derive(Clone, Default)] | ||
pub struct Runtime { | ||
pub(crate) inner: Rc<RefCell<RuntimeInner>>, | ||
} | ||
|
||
impl Runtime { | ||
pub fn enter(&self) { | ||
CONTEXT | ||
.try_with(|cell| *cell.borrow_mut() = Some(self.clone())) | ||
.unwrap(); | ||
} | ||
|
||
pub fn current() -> Self { | ||
CONTEXT | ||
.try_with(|cell| cell.borrow().as_ref().unwrap().clone()) | ||
.unwrap() | ||
} | ||
} | ||
|
||
thread_local! { | ||
static CONTEXT: RefCell<Option<Runtime>> = RefCell::new(None); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.