fmt: apply formatting just to tests

This commit is contained in:
Jonathan Kelley committed 2022-01-31 02:44:16 -05:00
1 parent 5bffbba682
commit 00aa0e5e86
7 files changed
+119 -38

No files matched your search

+3 -1
View File
@@ -12,7 +12,9 @@ pub(crate) struct BubbleState {
impl BubbleState { impl BubbleState {
pub fn new() -> Self { pub fn new() -> Self {
Self { canceled: Cell::new(false) } Self {
canceled: Cell::new(false),
}
} }
} }
+22 -5
View File
@@ -55,7 +55,9 @@ impl<'a, 'b> LazyNodes<'a, 'b> {
fac.map(inner) fac.map(inner)
}; };
Self { inner: StackNodeStorage::Heap(Box::new(val)) } Self {
inner: StackNodeStorage::Heap(Box::new(val)),
}
} }
pub fn new(_val: impl FnOnce(NodeFactory<'a>) -> VNode<'a> + 'b) -> Self { pub fn new(_val: impl FnOnce(NodeFactory<'a>) -> VNode<'a> + 'b) -> Self {
@@ -69,7 +71,9 @@ impl<'a, 'b> LazyNodes<'a, 'b> {
// miri does not know how to work with mucking directly into bytes // miri does not know how to work with mucking directly into bytes
if cfg!(miri) { if cfg!(miri) {
Self { inner: StackNodeStorage::Heap(Box::new(val)) } Self {
inner: StackNodeStorage::Heap(Box::new(val)),
}
} else { } else {
unsafe { LazyNodes::new_inner(val) } unsafe { LazyNodes::new_inner(val) }
} }
@@ -113,7 +117,9 @@ impl<'a, 'b> LazyNodes<'a, 'b> {
let max_size = mem::size_of::<StackHeapSize>(); let max_size = mem::size_of::<StackHeapSize>();
if stored_size > max_size { if stored_size > max_size {
Self { inner: StackNodeStorage::Heap(Box::new(val)) } Self {
inner: StackNodeStorage::Heap(Box::new(val)),
}
} else { } else {
let mut buf: StackHeapSize = StackHeapSize::default(); let mut buf: StackHeapSize = StackHeapSize::default();
@@ -137,7 +143,13 @@ impl<'a, 'b> LazyNodes<'a, 'b> {
std::mem::forget(val); std::mem::forget(val);
Self { inner: StackNodeStorage::Stack(LazyStack { _align: [], buf, dropped: false }) } Self {
inner: StackNodeStorage::Stack(LazyStack {
_align: [],
buf,
dropped: false,
}),
}
} }
} }
@@ -286,7 +298,12 @@ mod tests {
} }
let inner = Rc::new(0); let inner = Rc::new(0);
let mut dom = VirtualDom::new_with_props(app, AppProps { inner: inner.clone() }); let mut dom = VirtualDom::new_with_props(
app,
AppProps {
inner: inner.clone(),
},
);
dom.rebuild(); dom.rebuild();
drop(dom); drop(dom);
+27 -7
View File
@@ -115,7 +115,11 @@ use DomEdit::*;
impl<'a> Mutations<'a> { impl<'a> Mutations<'a> {
pub(crate) fn new() -> Self { pub(crate) fn new() -> Self {
Self { edits: Vec::new(), refs: Vec::new(), diffed_scopes: Default::default() } Self {
edits: Vec::new(),
refs: Vec::new(),
diffed_scopes: Default::default(),
}
} }
// Navigation // Navigation
@@ -174,12 +178,19 @@ impl<'a> Mutations<'a> {
// events // events
pub(crate) fn new_event_listener(&mut self, listener: &Listener, scope: ScopeId) { pub(crate) fn new_event_listener(&mut self, listener: &Listener, scope: ScopeId) {
let Listener { event, mounted_node, .. } = listener; let Listener {
event,
mounted_node,
..
} = listener;
let element_id = mounted_node.get().unwrap().as_u64(); let element_id = mounted_node.get().unwrap().as_u64();
self.edits self.edits.push(NewEventListener {
.push(NewEventListener { scope, event_name: event, root: element_id }); scope,
event_name: event,
root: element_id,
});
} }
pub(crate) fn remove_event_listener(&mut self, event: &'static str, root: u64) { pub(crate) fn remove_event_listener(&mut self, event: &'static str, root: u64) {
self.edits.push(RemoveEventListener { event, root }); self.edits.push(RemoveEventListener { event, root });
@@ -191,10 +202,19 @@ impl<'a> Mutations<'a> {
} }
pub(crate) fn set_attribute(&mut self, attribute: &'a Attribute, root: u64) { pub(crate) fn set_attribute(&mut self, attribute: &'a Attribute, root: u64) {
let Attribute { name, value, namespace, .. } = attribute; let Attribute {
name,
value,
namespace,
..
} = attribute;
self.edits self.edits.push(SetAttribute {
.push(SetAttribute { field: name, value, ns: *namespace, root }); field: name,
value,
ns: *namespace,
root,
});
} }
pub(crate) fn remove_attribute(&mut self, attribute: &Attribute, root: u64) { pub(crate) fn remove_attribute(&mut self, attribute: &Attribute, root: u64) {
+41 -17
View File
@@ -365,7 +365,9 @@ pub struct EventHandler<'bump, T = ()> {
impl<'a, T> Default for EventHandler<'a, T> { impl<'a, T> Default for EventHandler<'a, T> {
fn default() -> Self { fn default() -> Self {
Self { callback: RefCell::new(None) } Self {
callback: RefCell::new(None),
}
} }
} }
@@ -440,7 +442,10 @@ pub struct NodeFactory<'a> {
impl<'a> NodeFactory<'a> { impl<'a> NodeFactory<'a> {
pub fn new(scope: &'a ScopeState) -> NodeFactory<'a> { pub fn new(scope: &'a ScopeState) -> NodeFactory<'a> {
NodeFactory { scope, bump: &scope.wip_frame().bump } NodeFactory {
scope,
bump: &scope.wip_frame().bump,
}
} }
#[inline] #[inline]
@@ -450,10 +455,11 @@ impl<'a> NodeFactory<'a> {
/// Directly pass in text blocks without the need to use the format_args macro. /// Directly pass in text blocks without the need to use the format_args macro.
pub fn static_text(&self, text: &'static str) -> VNode<'a> { pub fn static_text(&self, text: &'static str) -> VNode<'a> {
VNode::Text( VNode::Text(self.bump.alloc(VText {
self.bump id: empty_cell(),
.alloc(VText { id: empty_cell(), text, is_static: true }), text,
) is_static: true,
}))
} }
/// Parses a lazy text Arguments and returns a string and a flag indicating if the text is 'static /// Parses a lazy text Arguments and returns a string and a flag indicating if the text is 'static
@@ -476,7 +482,11 @@ impl<'a> NodeFactory<'a> {
pub fn text(&self, args: Arguments) -> VNode<'a> { pub fn text(&self, args: Arguments) -> VNode<'a> {
let (text, is_static) = self.raw_text(args); let (text, is_static) = self.raw_text(args);
VNode::Text(self.bump.alloc(VText { text, is_static, id: empty_cell() })) VNode::Text(self.bump.alloc(VText {
text,
is_static,
id: empty_cell(),
}))
} }
pub fn element( pub fn element(
@@ -534,7 +544,13 @@ impl<'a> NodeFactory<'a> {
is_volatile: bool, is_volatile: bool,
) -> Attribute<'a> { ) -> Attribute<'a> {
let (value, is_static) = self.raw_text(val); let (value, is_static) = self.raw_text(val);
Attribute { name, value, is_static, namespace, is_volatile } Attribute {
name,
value,
is_static,
namespace,
is_volatile,
}
} }
pub fn component<P>( pub fn component<P>(
@@ -578,7 +594,11 @@ impl<'a> NodeFactory<'a> {
} }
pub fn listener(self, event: &'static str, callback: InternalHandler<'a>) -> Listener<'a> { pub fn listener(self, event: &'static str, callback: InternalHandler<'a>) -> Listener<'a> {
Listener { event, mounted_node: Cell::new(None), callback } Listener {
event,
mounted_node: Cell::new(None),
callback,
}
} }
pub fn fragment_root<'b, 'c>( pub fn fragment_root<'b, 'c>(
@@ -594,10 +614,10 @@ impl<'a> NodeFactory<'a> {
if nodes.is_empty() { if nodes.is_empty() {
VNode::Placeholder(self.bump.alloc(VPlaceholder { id: empty_cell() })) VNode::Placeholder(self.bump.alloc(VPlaceholder { id: empty_cell() }))
} else { } else {
VNode::Fragment( VNode::Fragment(self.bump.alloc(VFragment {
self.bump children: nodes.into_bump_slice(),
.alloc(VFragment { children: nodes.into_bump_slice(), key: None }), key: None,
) }))
} }
} }
@@ -633,7 +653,10 @@ impl<'a> NodeFactory<'a> {
); );
} }
VNode::Fragment(self.bump.alloc(VFragment { children, key: None })) VNode::Fragment(self.bump.alloc(VFragment {
children,
key: None,
}))
} }
} }
@@ -656,9 +679,10 @@ impl<'a> NodeFactory<'a> {
} else { } else {
let children = nodes.into_bump_slice(); let children = nodes.into_bump_slice();
Some(VNode::Fragment( Some(VNode::Fragment(self.bump.alloc(VFragment {
self.bump.alloc(VFragment { children, key: None }), children,
)) key: None,
})))
} }
} }
+22 -7
View File
@@ -315,9 +315,11 @@ impl ScopeArena {
frame.node.set(unsafe { extend_vnode(node) }); frame.node.set(unsafe { extend_vnode(node) });
} else { } else {
let frame = scope.wip_frame(); let frame = scope.wip_frame();
let node = frame.bump.alloc(VNode::Placeholder( let node = frame
frame.bump.alloc(VPlaceholder { id: Default::default() }), .bump
)); .alloc(VNode::Placeholder(frame.bump.alloc(VPlaceholder {
id: Default::default(),
})));
frame.node.set(unsafe { extend_vnode(node) }); frame.node.set(unsafe { extend_vnode(node) });
} }
@@ -427,7 +429,10 @@ pub struct Scope<'a, P = ()> {
impl<P> Copy for Scope<'_, P> {} impl<P> Copy for Scope<'_, P> {}
impl<P> Clone for Scope<'_, P> { impl<P> Clone for Scope<'_, P> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { scope: self.scope, props: self.props } Self {
scope: self.scope,
props: self.props,
}
} }
} }
@@ -789,7 +794,10 @@ impl ScopeState {
/// } /// }
///``` ///```
pub fn render<'src>(&'src self, rsx: LazyNodes<'src, '_>) -> Option<VNode<'src>> { pub fn render<'src>(&'src self, rsx: LazyNodes<'src, '_>) -> Option<VNode<'src>> {
Some(rsx.call(NodeFactory { scope: self, bump: &self.wip_frame().bump })) Some(rsx.call(NodeFactory {
scope: self,
bump: &self.wip_frame().bump,
}))
} }
/// Store a value between renders /// Store a value between renders
@@ -896,7 +904,10 @@ impl ScopeState {
self.shared_contexts.get_mut().clear(); self.shared_contexts.get_mut().clear();
// next: reset the node data // next: reset the node data
let SelfReferentialItems { borrowed_props, listeners } = self.items.get_mut(); let SelfReferentialItems {
borrowed_props,
listeners,
} = self.items.get_mut();
borrowed_props.clear(); borrowed_props.clear();
listeners.clear(); listeners.clear();
self.frames[0].reset(); self.frames[0].reset();
@@ -954,7 +965,11 @@ pub(crate) struct TaskQueue {
pub(crate) type InnerTask = Pin<Box<dyn Future<Output = ()>>>; pub(crate) type InnerTask = Pin<Box<dyn Future<Output = ()>>>;
impl TaskQueue { impl TaskQueue {
fn new(sender: UnboundedSender<SchedulerMsg>) -> Rc<Self> { fn new(sender: UnboundedSender<SchedulerMsg>) -> Rc<Self> {
Rc::new(Self { tasks: RefCell::new(FxHashMap::default()), gen: Cell::new(0), sender }) Rc::new(Self {
tasks: RefCell::new(FxHashMap::default()),
gen: Cell::new(0),
sender,
})
} }
fn push_fut(&self, task: impl Future<Output = ()> + 'static) -> TaskId { fn push_fut(&self, task: impl Future<Output = ()> + 'static) -> TaskId {
let pinned = Box::pin(task); let pinned = Box::pin(task);
+4 -1
View File
@@ -10,7 +10,10 @@ pub struct ElementIdIterator<'a> {
impl<'a> ElementIdIterator<'a> { impl<'a> ElementIdIterator<'a> {
pub fn new(vdom: &'a VirtualDom, node: &'a VNode<'a>) -> Self { pub fn new(vdom: &'a VirtualDom, node: &'a VNode<'a>) -> Self {
Self { vdom, stack: smallvec::smallvec![(0, node)] } Self {
vdom,
stack: smallvec::smallvec![(0, node)],
}
} }
} }
File renamed without changes.