Feat: desktop app wired up

This commit is contained in:
Jonathan Kelley committed 2021-02-18 20:04:25 -05:00
1 parent bcbb93b697
commit b3e6886351
10 files changed
+744 -269

No files matched your search

+13 -7
View File
@@ -19,6 +19,8 @@
//!
//!
use std::ops::{Deref, DerefMut};
use bumpalo::Bump;
use crate::innerlude::{Listener, VirtualDom};
@@ -32,8 +34,9 @@ use crate::innerlude::{Listener, VirtualDom};
///
///
///
///
#[derive(Debug)]
/// todo@ jon: allow serde to be optional
#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[serde(tag = "type")]
pub enum Edit<'d> {
SetText { text: &'d str },
RemoveSelfAndNextSiblings {},
@@ -59,20 +62,23 @@ pub enum Edit<'d> {
SetClass { class_name: &'d str },
}
pub struct EditList<'src> {
pub type EditList<'src> = Vec<Edit<'src>>;
pub struct EditMachine<'src> {
pub traversal: Traversal,
next_temporary: u32,
forcing_new_listeners: bool,
pub emitter: Vec<Edit<'src>>,
pub emitter: EditList<'src>,
}
impl<'b> EditList<'b> {
impl<'b> EditMachine<'b> {
pub fn new(bump: &'b Bump) -> Self {
Self {
traversal: Traversal::new(),
next_temporary: 0,
forcing_new_listeners: false,
emitter: Vec::new(),
emitter: EditList::default(),
}
}
@@ -153,7 +159,7 @@ impl<'b> EditList<'b> {
}
}
impl<'a> EditList<'a> {
impl<'a> EditMachine<'a> {
pub fn next_temporary(&self) -> u32 {
self.next_temporary
}
+4 -4
View File
@@ -37,7 +37,7 @@ use fxhash::{FxHashMap, FxHashSet};
use generational_arena::Index;
use crate::{
changelist::{Edit, EditList},
changelist::{Edit, EditList, EditMachine},
innerlude::{Attribute, Listener, Scope, VElement, VNode, VText},
virtual_dom::LifecycleEvent,
};
@@ -57,7 +57,7 @@ use std::cmp::Ordering;
/// that were modified by the eventtrigger. This prevents doubly evaluating components if they wereboth updated via
/// subscriptions and props changes.
pub struct DiffMachine<'a> {
pub change_list: EditList<'a>,
pub change_list: EditMachine<'a>,
immediate_queue: Vec<Index>,
diffed: FxHashSet<Index>,
need_to_diff: FxHashSet<Index>,
@@ -71,14 +71,14 @@ enum NeedToDiff {
impl<'a> DiffMachine<'a> {
pub fn new(bump: &'a Bump) -> Self {
Self {
change_list: EditList::new(bump),
change_list: EditMachine::new(bump),
immediate_queue: Vec::new(),
diffed: FxHashSet::default(),
need_to_diff: FxHashSet::default(),
}
}
pub fn consume(self) -> Vec<Edit<'a>> {
pub fn consume(self) -> EditList<'a> {
self.change_list.emitter
}
+5
View File
@@ -19,6 +19,11 @@ impl EventTrigger {
}
pub enum VirtualEvent {
// the event to drain the current lifecycle queue
// Used to initate the dom
InitiateEvent,
// Real events
ClipboardEvent,
CompositionEvent,
KeyboardEvent,
+16 -20
View File
@@ -21,7 +21,8 @@ use std::{
///
/// Scopes are allocated in a generational arena. As components are mounted/unmounted, they will replace slots of dead components.
/// The actual contents of the hooks, though, will be allocated with the standard allocator. These should not allocate as frequently.
pub(crate) struct Scope {
pub struct Scope {
// pub(crate) struct Scope {
// TODO @Jon
// These hooks are actually references into the hook arena
// These two could be combined with "OwningRef" to remove unsafe usage
@@ -50,23 +51,10 @@ pub(crate) struct Scope {
pub caller: *const i32,
}
// pub enum ActiveFrame {
// First,
// Second,
// }
// impl ActiveFrame {
// fn next(&mut self) {
// match self {
// ActiveFrame::First => *self = ActiveFrame::Second,
// ActiveFrame::Second => *self = ActiveFrame::First,
// }
// }
// }
impl Scope {
// create a new scope from a function
pub(crate) fn new<T: 'static>(
pub fn new<T: 'static>(
// pub(crate) fn new<T: 'static>(
f: FC<T>,
props: impl Properties + 'static,
parent: Option<Index>,
@@ -120,7 +108,7 @@ impl Scope {
/// This function downcasts the function pointer based on the stored props_type
///
/// Props is ?Sized because we borrow the props and don't need to know the size. P (sized) is used as a marker (unsized)
pub(crate) fn run<'bump, P: Properties + Sized + 'static>(&'bump mut self) {
pub fn run<'bump, P: Properties + Sized + 'static>(&'bump mut self) {
let frame = {
let frame = self.frames.next();
frame.bump.reset();
@@ -164,14 +152,12 @@ impl Scope {
let unsafe_node = unsafe { std::mem::transmute::<VNode<'bump>, VNode<'static>>(nodes) };
frame.head_node = unsafe_node;
todo!()
}
/// Accessor to get the root node and its children (safely)\
/// Scope is self-referntial, so we are forced to use the 'static lifetime to cheat
pub fn current_root_node<'bump>(&'bump self) -> &'bump VNode<'bump> {
todo!()
self.frames.current_head_node()
}
pub fn prev_root_node<'bump>(&'bump self) -> &'bump VNode<'bump> {
todo!()
@@ -196,6 +182,16 @@ impl ActiveFrame {
}
}
fn current_head_node<'b>(&'b self) -> &'b VNode<'b> {
let cur_idx = self.idx.borrow().load(std::sync::atomic::Ordering::Relaxed);
let raw_node = &self.frames[cur_idx];
unsafe {
let unsafe_head = &raw_node.head_node;
let safe_node = std::mem::transmute::<&VNode<'static>, &VNode<'b>>(unsafe_head);
safe_node
}
}
fn next(&mut self) -> &mut BumpFrame {
self.idx.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
let cur = self.idx.borrow().load(std::sync::atomic::Ordering::Relaxed);
+9 -7
View File
@@ -1,8 +1,9 @@
// use crate::{changelist::EditList, nodes::VNode};
use crate::{dodriodiff::DiffMachine, nodes::VNode};
use crate::{changelist::{self, EditList}, dodriodiff::DiffMachine, nodes::VNode};
use crate::{events::EventTrigger, innerlude::*};
use any::Any;
use bumpalo::Bump;
use changelist::EditMachine;
use generational_arena::{Arena, Index};
use std::{
any::{self, TypeId},
@@ -105,6 +106,10 @@ impl VirtualDom {
/// This lets services external to the virtual dom interact directly with the component and event system.
pub fn queue_update() {}
pub fn start(&mut self) -> Result<EditList> {
todo!()
}
/// Pop an event off the event queue and process it
/// Update the root props, and progress
/// Takes a bump arena to allocate into, making the diff phase as fast as possible
@@ -115,7 +120,7 @@ impl VirtualDom {
.borrow_mut()
.pop_front()
.ok_or(Error::NoEvent)?;
self.process_event(event)
self.process_lifecycle(event)
}
/// This method is the most sophisticated way of updating the virtual dom after an external event has been triggered.
@@ -171,7 +176,7 @@ impl VirtualDom {
new_evt
} {
affected_components.push(event.component_index);
self.process_event(event)?;
self.process_lifecycle(event)?;
}
let diff_bump = Bump::new();
@@ -180,9 +185,6 @@ impl VirtualDom {
Ok(())
}
pub async fn progress_completely(&mut self) -> Result<()> {
Ok(())
}
/// Using mutable access to the Virtual Dom, progress a given lifecycle event
///
///
@@ -190,7 +192,7 @@ impl VirtualDom {
///
///
///
fn process_event(
fn process_lifecycle(
&mut self,
LifecycleEvent {
component_index: index,