Skip to content

Commit

Permalink
Implement Default for Children
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechu10 committed Sep 20, 2022
1 parent b48d3f2 commit d9c3fc6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/sycamore-core/src/component.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Utilities for components and component properties.
use std::fmt;

use sycamore_reactive::*;

use crate::generic_node::GenericNode;
Expand Down Expand Up @@ -93,8 +95,8 @@ pub fn element_like_component_builder<'a, T: Prop + 'a, G: GenericNode>(
pub struct Children<'a, G: GenericNode> {
f: Box<dyn FnOnce(BoundedScope<'_, 'a>) -> View<G> + 'a>,
}
impl<'a, G: GenericNode> std::fmt::Debug for Children<'a, G> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl<'a, G: GenericNode> fmt::Debug for Children<'a, G> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Children").finish()
}
}
Expand All @@ -108,6 +110,14 @@ where
}
}

impl<'a, G: GenericNode> Default for Children<'a, G> {
fn default() -> Self {
Self {
f: Box::new(|_| View::default()),
}
}
}

impl<'a, G: GenericNode> Children<'a, G> {
/// Instantiate the child [`View`] with the passed [`Scope`].
pub fn call(self, cx: BoundedScope<'_, 'a>) -> View<G> {
Expand Down

0 comments on commit d9c3fc6

Please sign in to comment.