feat: integrate serialization and string borrowing

This commit adds lifetimes to the diff and realdom methods so consumers may borrow the contents of the DOM for serialization or asynchronous modifications.
This commit is contained in:
Jonathan Kelley committed 2021-06-28 12:05:17 -04:00
1 parent 9813f23cdf
commit f4fb5bb454
12 files changed
+480 -86

No files matched your search

+70 -1
View File
@@ -21,6 +21,75 @@ enum MutStatus {
Mut,
}
// impl ScopeArenaInner {
// pub fn new(arena: Arena<Scope>) -> Self {
// ScopeArenaInner {
// arena: UnsafeCell::new(arena),
// locks: Default::default(),
// }
// }
// /// THIS METHOD IS CURRENTLY UNSAFE
// /// THERE ARE NO CHECKS TO VERIFY THAT WE ARE ALLOWED TO DO THIS
// pub fn try_get(&self, idx: ScopeIdx) -> Result<&Scope> {
// let inner = unsafe { &*self.arena.get() };
// let scope = inner.get(idx);
// scope.ok_or_else(|| Error::FatalInternal("Scope not found"))
// }
// /// THIS METHOD IS CURRENTLY UNSAFE
// /// THERE ARE NO CHECKS TO VERIFY THAT WE ARE ALLOWED TO DO THIS
// pub fn try_get_mut(&self, idx: ScopeIdx) -> Result<&mut Scope> {
// let inner = unsafe { &mut *self.arena.get() };
// let scope = inner.get_mut(idx);
// scope.ok_or_else(|| Error::FatalInternal("Scope not found"))
// }
// fn inner(&self) -> &Arena<Scope> {
// todo!()
// }
// fn inner_mut(&mut self) -> &mut Arena<Scope> {
// todo!()
// }
// /// THIS METHOD IS CURRENTLY UNSAFE
// /// THERE ARE NO CHECKS TO VERIFY THAT WE ARE ALLOWED TO DO THIS
// pub fn with<T>(&self, f: impl FnOnce(&mut Arena<Scope>) -> T) -> Result<T> {
// let inner = unsafe { &mut *self.arena.get() };
// Ok(f(inner))
// // todo!()
// }
// pub fn with_scope<'b, O: 'static>(
// &'b self,
// id: ScopeIdx,
// f: impl FnOnce(&'b mut Scope) -> O,
// ) -> Result<O> {
// todo!()
// }
// // return a bumpframe with a lifetime attached to the arena borrow
// // this is useful for merging lifetimes
// pub fn with_scope_vnode<'b>(
// &self,
// id: ScopeIdx,
// f: impl FnOnce(&mut Scope) -> &VNode<'b>,
// ) -> Result<&VNode<'b>> {
// todo!()
// }
// pub fn try_remove(&mut self, id: ScopeIdx) -> Result<Scope> {
// let inner = unsafe { &mut *self.arena.get() };
// inner
// .remove(id)
// .ok_or_else(|| Error::FatalInternal("Scope not found"))
// }
// unsafe fn inner_unchecked<'s>() -> &'s mut Arena<Scope> {
// todo!()
// }
// }
impl ScopeArena {
pub fn new(arena: Arena<Scope>) -> Self {
ScopeArena(Rc::new(RefCell::new(ScopeArenaInner {
@@ -79,7 +148,7 @@ impl ScopeArena {
todo!()
}
pub fn try_remove(&mut self, id: ScopeIdx) -> Result<Scope> {
pub fn try_remove(&self, id: ScopeIdx) -> Result<Scope> {
let inner = unsafe { &mut *self.0.borrow().arena.get() };
inner
.remove(id)