use silex_core::reactivity::ReadSignal;
use silex_core::traits::{ForLoopSource, RxRead};
use silex_dom::prelude::*;
use silex_macros::component;
use std::rc::Rc;
#[component]
pub fn Index<IF, I, IS, MF, V>(
each: IF,
#[prop(render)]
#[chain]
children: MF,
) -> impl View
where
IF: RxRead<Value = IS> + Clone + 'static,
IS: ForLoopSource<Item = I> + 'static,
MF: Fn(ReadSignal<I>, ReadSignal<usize>) -> V + Clone + 'static,
V: View + 'static,
I: Clone + 'static,
{
let view_fn = Rc::new(move |item: ReadSignal<I>, index: ReadSignal<usize>| {
children(item, index).into_any()
});
silex_dom::view::list::IndexedLoopView {
each,
view_fn,
_marker: std::marker::PhantomData,
}
}