mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 14:54:16 +00:00
added IntoFragment
trait for all IntoIterator
and also impl FromIterator
for Fragment
This commit is contained in:
parent
0b11a8dda6
commit
e2ef293d19
2 changed files with 31 additions and 1 deletions
|
@ -1,9 +1,39 @@
|
||||||
|
use leptos_reactive::Scope;
|
||||||
|
|
||||||
use crate::{ComponentRepr, IntoView, View};
|
use crate::{ComponentRepr, IntoView, View};
|
||||||
|
|
||||||
|
/// Trait for converting any iterable into a [`Fragment`].
|
||||||
|
pub trait IntoFragment {
|
||||||
|
/// Consumes this type, returning [`Fragment`].
|
||||||
|
fn into_fragment(self, cx: Scope) -> Fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I, V> IntoFragment for I
|
||||||
|
where
|
||||||
|
I: IntoIterator<Item = V>,
|
||||||
|
V: IntoView,
|
||||||
|
{
|
||||||
|
fn into_fragment(self, cx: Scope) -> Fragment {
|
||||||
|
self.into_iter().map(|v| v.into_view(cx)).collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents a group of [`views`](View).
|
/// Represents a group of [`views`](View).
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Fragment(Vec<View>);
|
pub struct Fragment(Vec<View>);
|
||||||
|
|
||||||
|
impl FromIterator<View> for Fragment {
|
||||||
|
fn from_iter<T: IntoIterator<Item = View>>(iter: T) -> Self {
|
||||||
|
Fragment::new(iter.into_iter().collect())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<View> for Fragment {
|
||||||
|
fn from(view: View) -> Self {
|
||||||
|
Fragment::new(vec![view])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Fragment {
|
impl Fragment {
|
||||||
/// Creates a new [`Fragment`] from a [`Vec<Node>`].
|
/// Creates a new [`Fragment`] from a [`Vec<Node>`].
|
||||||
pub fn new(nodes: Vec<View>) -> Self {
|
pub fn new(nodes: Vec<View>) -> Self {
|
||||||
|
|
|
@ -24,8 +24,8 @@ pub use components::*;
|
||||||
pub use events::typed as ev;
|
pub use events::typed as ev;
|
||||||
pub use helpers::*;
|
pub use helpers::*;
|
||||||
pub use html::*;
|
pub use html::*;
|
||||||
pub use js_sys;
|
|
||||||
use hydration::HydrationCtx;
|
use hydration::HydrationCtx;
|
||||||
|
pub use js_sys;
|
||||||
use leptos_reactive::Scope;
|
use leptos_reactive::Scope;
|
||||||
pub use logging::*;
|
pub use logging::*;
|
||||||
pub use node_ref::*;
|
pub use node_ref::*;
|
||||||
|
|
Loading…
Reference in a new issue