wip: some ideas
This commit is contained in:
1 parent
583fdfa561
commit
05c909f320
21 files changed
+662
-1112
No files matched your search
@@ -22,18 +22,16 @@ impl SharedArena {
|
||||
|
||||
/// THIS METHOD IS CURRENTLY UNSAFE
|
||||
/// THERE ARE NO CHECKS TO VERIFY THAT WE ARE ALLOWED TO DO THIS
|
||||
pub fn try_get(&self, idx: ScopeId) -> Result<&Scope> {
|
||||
pub fn get(&self, idx: ScopeId) -> Option<&Scope> {
|
||||
let inner = unsafe { &*self.components.get() };
|
||||
let scope = inner.get(idx);
|
||||
scope.ok_or_else(|| Error::FatalInternal("Scope not found"))
|
||||
inner.get(idx)
|
||||
}
|
||||
|
||||
/// 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: ScopeId) -> Result<&mut Scope> {
|
||||
pub fn get_mut(&self, idx: ScopeId) -> Option<&mut Scope> {
|
||||
let inner = unsafe { &mut *self.components.get() };
|
||||
let scope = inner.get_mut(idx);
|
||||
scope.ok_or_else(|| Error::FatalInternal("Scope not found"))
|
||||
inner.get_mut(idx)
|
||||
}
|
||||
|
||||
fn inner(&self) -> &ScopeMap {
|
||||
|
||||
@@ -278,8 +278,8 @@ Any function prefixed with "use" should not be called conditionally.
|
||||
Some(parent_id) => {
|
||||
let parent = inner
|
||||
.arena_link
|
||||
.try_get(parent_id)
|
||||
.map_err(|_| Error::FatalInternal("Failed to find parent"))?;
|
||||
.get(parent_id)
|
||||
.ok_or_else(|| Error::FatalInternal("Failed to find parent"))?;
|
||||
|
||||
scope = Some(parent);
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ where
|
||||
new.ass_scope.set(scope_id);
|
||||
|
||||
// make sure the component's caller function is up to date
|
||||
let scope = self.components.try_get_mut(scope_id.unwrap()).unwrap();
|
||||
let scope = self.components.get_mut(scope_id.unwrap()).unwrap();
|
||||
|
||||
scope.caller = new.caller.clone();
|
||||
|
||||
@@ -406,7 +406,7 @@ where
|
||||
.components
|
||||
.with(|components| {
|
||||
components.insert_with_key(|new_idx| {
|
||||
let parent_scope = self.components.try_get(parent_idx).unwrap();
|
||||
let parent_scope = self.components.get(parent_idx).unwrap();
|
||||
let height = parent_scope.height + 1;
|
||||
Scope::new(
|
||||
caller,
|
||||
@@ -495,7 +495,7 @@ impl<'a, 'bump, Dom: RealDom<'bump>> DiffMachine<'a, 'bump, Dom> {
|
||||
while let Some(scope_id) = scopes_to_explore.pop() {
|
||||
// If we're planning on deleting this node, then we don't need to both rendering it
|
||||
self.seen_nodes.insert(scope_id);
|
||||
let scope = self.components.try_get(scope_id).unwrap();
|
||||
let scope = self.components.get(scope_id).unwrap();
|
||||
for child in scope.descendents.borrow().iter() {
|
||||
// Add this node to be explored
|
||||
scopes_to_explore.push(child.clone());
|
||||
@@ -1324,7 +1324,7 @@ impl<'a> Iterator for RealChildIterator<'a> {
|
||||
|
||||
// For components, we load their root and push them onto the stack
|
||||
VNodeKind::Component(sc) => {
|
||||
let scope = self.scopes.try_get(sc.ass_scope.get().unwrap()).unwrap();
|
||||
let scope = self.scopes.get(sc.ass_scope.get().unwrap()).unwrap();
|
||||
|
||||
// Simply swap the current node on the stack with the root of the component
|
||||
*node = scope.root();
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
//!
|
||||
|
||||
pub use crate::innerlude::{
|
||||
format_args_f, html, rsx, DioxusElement, DomEdit, EventTrigger, LazyNodes, NodeFactory,
|
||||
Properties, RealDom, RealDomNode, ScopeId, VNode, VNodeKind, VirtualDom, VirtualEvent, FC,
|
||||
format_args_f, html, rsx, Context, DioxusElement, DomEdit, EventTrigger, LazyNodes,
|
||||
NodeFactory, Properties, RealDom, RealDomNode, ScopeId, VNode, VNodeKind, VirtualDom,
|
||||
VirtualEvent, FC,
|
||||
};
|
||||
|
||||
pub mod prelude {
|
||||
|
||||
@@ -224,7 +224,7 @@ impl VirtualDom {
|
||||
&self.tasks,
|
||||
);
|
||||
|
||||
let cur_component = self.components.try_get_mut(self.base_scope).unwrap();
|
||||
let cur_component = self.components.get_mut(self.base_scope).unwrap();
|
||||
cur_component.run_scope()?;
|
||||
|
||||
let meta = diff_machine.create(cur_component.next_frame());
|
||||
@@ -312,7 +312,7 @@ impl VirtualDom {
|
||||
|
||||
// Suspense Events! A component's suspended node is updated
|
||||
VirtualEvent::SuspenseEvent { hook_idx, domnode } => {
|
||||
let scope = self.components.try_get_mut(trigger.originator).unwrap();
|
||||
let scope = self.components.get_mut(trigger.originator).unwrap();
|
||||
|
||||
// safety: we are sure that there are no other references to the inner content of this hook
|
||||
let hook = unsafe { scope.hooks.get_mut::<SuspenseHook>(*hook_idx) }.unwrap();
|
||||
@@ -339,8 +339,8 @@ impl VirtualDom {
|
||||
// We use the reconciler to request new IDs and then commit/uncommit the IDs when the scheduler is finished
|
||||
_ => {
|
||||
self.components
|
||||
.try_get_mut(trigger.originator)?
|
||||
.call_listener(trigger)?;
|
||||
.get_mut(trigger.originator)
|
||||
.map(|f| f.call_listener(trigger));
|
||||
|
||||
// Now, there are events in the queue
|
||||
let mut updates = self.event_queue.queue.as_ref().borrow_mut();
|
||||
@@ -366,7 +366,7 @@ impl VirtualDom {
|
||||
|
||||
// Start a new mutable borrow to components
|
||||
// We are guaranteeed that this scope is unique because we are tracking which nodes have modified
|
||||
let cur_component = self.components.try_get_mut(update.idx).unwrap();
|
||||
let cur_component = self.components.get_mut(update.idx).unwrap();
|
||||
|
||||
cur_component.run_scope()?;
|
||||
|
||||
@@ -380,7 +380,7 @@ impl VirtualDom {
|
||||
}
|
||||
|
||||
pub fn base_scope(&self) -> &Scope {
|
||||
self.components.try_get(self.base_scope).unwrap()
|
||||
self.components.get(self.base_scope).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user