Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Mutations and simplify Templates #578

Merged
merged 57 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
f5b8650
pass clippy
ealmloff Oct 1, 2022
c1ce9ec
change mutations
ealmloff Oct 2, 2022
2330ab2
lazily init template node ids
ealmloff Oct 3, 2022
07af138
handle fragments
ealmloff Oct 3, 2022
01b9cc7
fix some lints
ealmloff Oct 3, 2022
d50e739
handle web implemenation
ealmloff Oct 3, 2022
1b30247
basic page loads working
ealmloff Oct 5, 2022
46eaf1e
remove globalNodeId
ealmloff Oct 6, 2022
c3e9403
work on listeners
ealmloff Oct 6, 2022
bdabdc8
fix some lints
ealmloff Oct 6, 2022
66ba849
clean up template diffing
ealmloff Oct 6, 2022
c71da45
improve diffing template refs
ealmloff Oct 7, 2022
01611ee
handle removing template refs
ealmloff Oct 7, 2022
68ffaa4
set template_ref_id of diffed template
ealmloff Oct 7, 2022
5c487d7
remove element_stack
ealmloff Oct 7, 2022
8add60f
handle first and last nodes of template ref for diffing lists
ealmloff Oct 7, 2022
f29ddcf
inline hot path function
ealmloff Oct 7, 2022
dd67270
fix insert after/before
ealmloff Oct 7, 2022
667ca14
fix get_all_real_nodes
ealmloff Oct 7, 2022
6010003
fix more template ref diffing errors
ealmloff Oct 7, 2022
8008fed
some optimizations
ealmloff Oct 7, 2022
b2307b2
pass clippy
ealmloff Oct 7, 2022
6512293
make liveview and ssr work
ealmloff Oct 7, 2022
355032d
optimize resolve_text
ealmloff Oct 7, 2022
0957e77
pass around mutatble vecs instead of creating many temporary vecs
ealmloff Oct 7, 2022
e2e2239
work on updating native core
ealmloff Oct 7, 2022
863f8d5
add remaining messages to native-core
ealmloff Oct 7, 2022
52daebd
work on native core macro
ealmloff Oct 7, 2022
dc1d164
update tui to work with new templates
ealmloff Oct 7, 2022
567a7e8
fix setting parent id when cloning nodes
ealmloff Oct 8, 2022
0e99851
mark nodes that are newly created as dirty
ealmloff Oct 8, 2022
c00d563
update child/parent links when last node is stored
ealmloff Oct 8, 2022
3080ff6
fix clone node with children
ealmloff Oct 8, 2022
1cfea7a
fix focus events triggering on events without ids
ealmloff Oct 8, 2022
29b008d
Merge branch 'master' into rework-templates
ealmloff Oct 8, 2022
5510cf6
fix tui focus
ealmloff Oct 8, 2022
edfeaf4
fix some warnings
ealmloff Oct 8, 2022
e21b1a4
generate paths at compile time
ealmloff Oct 8, 2022
ae2a745
update ssr
ealmloff Oct 8, 2022
cc103b2
fix desktop
ealmloff Oct 8, 2022
b158057
update dioxus tests
ealmloff Oct 9, 2022
108522e
update native core tests
ealmloff Oct 9, 2022
00e6150
fix rendering dynamic nodes in templates in native core
ealmloff Oct 10, 2022
6fdb726
update tests
ealmloff Oct 10, 2022
3b41c8a
Merge branch 'master' into rework-templates
ealmloff Oct 13, 2022
9e28f1d
remove MAX_JS_INT
ealmloff Oct 13, 2022
28dc225
remove GlobalNodeId
ealmloff Oct 13, 2022
9825f60
create path to set ids of dynamic elements efficiently
ealmloff Oct 15, 2022
e33f2a0
update ssr without Path
ealmloff Oct 15, 2022
27be249
remove locally static
ealmloff Oct 15, 2022
e9ca9bb
staticly generate optimal template update instructions
ealmloff Oct 16, 2022
7a810ed
fix some bugs with updating templates
ealmloff Oct 16, 2022
54af65f
update tui_colorpicker to work with templates
ealmloff Oct 16, 2022
8de1bb7
Merge branch 'master' into rework-templates
ealmloff Oct 16, 2022
96366b2
fix some type coersion errors
ealmloff Oct 16, 2022
290fceb
handle temporary nodes in native-core
ealmloff Oct 16, 2022
5f0a101
update liveview
ealmloff Oct 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
574 changes: 332 additions & 242 deletions packages/core/src/diff.rs

Large diffs are not rendered by default.

57 changes: 27 additions & 30 deletions packages/core/src/dynamic_template_context.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::{marker::PhantomData, ops::Deref};
use std::{fmt::Write, marker::PhantomData, ops::Deref};

use once_cell::sync::Lazy;

use crate::{
template::{TemplateNodeId, TextTemplateSegment},
AttributeValue, Listener, VNode,
AttributeValue, Listener, TextTemplate, VNode,
};

/// A lazily initailized vector
Expand Down Expand Up @@ -96,28 +96,6 @@ where
nodes_with_listeners: listeners,
}
}

pub(crate) fn all_dynamic(&self) -> impl Iterator<Item = TemplateNodeId> + '_ {
self.nodes
.as_ref()
.iter()
.filter_map(|o| o.as_ref())
.chain(
self.text
.as_ref()
.iter()
.flat_map(|ids| ids.as_ref().iter()),
)
.copied()
.chain(
self.attributes
.as_ref()
.iter()
.flat_map(|ids| ids.as_ref().iter())
.map(|dynamic| dynamic.0),
)
.chain(self.nodes_with_listeners.as_ref().iter().copied())
}
}

/// A dynamic node mapping that is stack allocated
Expand Down Expand Up @@ -161,19 +139,38 @@ pub struct TemplateContext<'b> {

impl<'b> TemplateContext<'b> {
/// Resolve text segments to a string
pub fn resolve_text<TextSegments, Text>(&self, text: &TextSegments) -> String
pub fn resolve_text<TextSegments, Text>(
&self,
text: &TextTemplate<TextSegments, Text>,
) -> String
where
TextSegments: AsRef<[TextTemplateSegment<Text>]>,
Text: AsRef<str>,
{
let mut result = String::new();
for seg in text.as_ref() {
let mut result = String::with_capacity(text.min_size);
self.resolve_text_into(text, &mut result);
result
}

/// Resolve text and writes the result
pub fn resolve_text_into<TextSegments, Text>(
&self,
text: &TextTemplate<TextSegments, Text>,
result: &mut impl Write,
) where
TextSegments: AsRef<[TextTemplateSegment<Text>]>,
Text: AsRef<str>,
{
for seg in text.segments.as_ref() {
match seg {
TextTemplateSegment::Static(s) => result += s.as_ref(),
TextTemplateSegment::Dynamic(idx) => result += self.text_segments[*idx],
TextTemplateSegment::Static(s) => {
let _ = result.write_str(s.as_ref());
}
TextTemplateSegment::Dynamic(idx) => {
let _ = result.write_str(self.text_segments[*idx]);
}
}
}
result
}

/// Resolve an attribute value
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//!
//! This is all kinda WIP, but the bones are there.

use crate::{nodes::GlobalNodeId, ScopeId};
use crate::{ElementId, ScopeId};
use std::{any::Any, cell::Cell, fmt::Debug, rc::Rc, sync::Arc};

pub(crate) struct BubbleState {
Expand Down Expand Up @@ -58,7 +58,7 @@ pub struct UserEvent {
pub priority: EventPriority,

/// The optional real node associated with the trigger
pub element: Option<GlobalNodeId>,
pub element: Option<ElementId>,

/// The event type IE "onclick" or "onmouseover"
pub name: &'static str,
Expand Down
24 changes: 12 additions & 12 deletions packages/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ pub(crate) mod innerlude {
pub use crate::innerlude::{
AnyEvent, ArbitraryAttributeValue, Attribute, AttributeDiscription, AttributeValue,
CodeLocation, Component, DioxusElement, DomEdit, DynamicNodeMapping, Element, ElementId,
ElementIdIterator, EventHandler, EventPriority, GlobalNodeId, IntoAttributeValue, IntoVNode,
LazyNodes, Listener, Mutations, NodeFactory, OwnedAttributeValue, Properties,
RendererTemplateId, SchedulerMsg, Scope, ScopeId, ScopeState, StaticCodeLocation,
StaticDynamicNodeMapping, StaticTemplateNode, StaticTemplateNodes, TaskId, Template,
ElementIdIterator, EventHandler, EventPriority, IntoAttributeValue, IntoVNode, LazyNodes,
Listener, Mutations, NodeFactory, OwnedAttributeValue, PathSeg, Properties, RendererTemplateId,
SchedulerMsg, Scope, ScopeId, ScopeState, StaticCodeLocation, StaticDynamicNodeMapping,
StaticPathSeg, StaticTemplateNode, StaticTemplateNodes, StaticTraverse, TaskId, Template,
TemplateAttribute, TemplateAttributeValue, TemplateContext, TemplateElement, TemplateId,
TemplateNode, TemplateNodeId, TemplateNodeType, TemplateValue, TextTemplate,
TextTemplateSegment, UiEvent, UserEvent, VComponent, VElement, VFragment, VNode, VPlaceholder,
VText, VirtualDom, JS_MAX_INT,
TextTemplateSegment, UiEvent, UpdateOp, UserEvent, VComponent, VElement, VFragment, VNode,
VPlaceholder, VText, VirtualDom,
};
#[cfg(any(feature = "hot-reload", debug_assertions))]
pub use crate::innerlude::{
OwnedCodeLocation, OwnedDynamicNodeMapping, OwnedTemplateNode, OwnedTemplateNodes,
SetTemplateMsg,
OwnedCodeLocation, OwnedDynamicNodeMapping, OwnedPathSeg, OwnedTemplateNode,
OwnedTemplateNodes, OwnedTraverse, SetTemplateMsg,
};

/// The purpose of this module is to alleviate imports of many common types
Expand All @@ -95,10 +95,10 @@ pub mod prelude {
fc_to_builder, AttributeDiscription, AttributeValue, Attributes, CodeLocation, Component,
DioxusElement, Element, EventHandler, Fragment, IntoAttributeValue, LazyNodes,
LazyStaticVec, NodeFactory, Properties, Scope, ScopeId, ScopeState, StaticAttributeValue,
StaticCodeLocation, StaticDynamicNodeMapping, StaticTemplate, StaticTemplateNodes,
Template, TemplateAttribute, TemplateAttributeValue, TemplateContext, TemplateElement,
TemplateId, TemplateNode, TemplateNodeId, TemplateNodeType, TextTemplate,
TextTemplateSegment, VNode, VirtualDom,
StaticCodeLocation, StaticDynamicNodeMapping, StaticPathSeg, StaticTemplate,
StaticTemplateNodes, StaticTraverse, Template, TemplateAttribute, TemplateAttributeValue,
TemplateContext, TemplateElement, TemplateId, TemplateNode, TemplateNodeId,
TemplateNodeType, TextTemplate, TextTemplateSegment, UpdateOp, VNode, VirtualDom,
};
}

Expand Down
Loading