Pauan / rust-dominator

Zero-cost ultra-high-performance declarative DOM library using FRP signals for Rust!
MIT License
967 stars 62 forks source link

Signal of HTML elements #20

Closed joonazan closed 4 years ago

joonazan commented 4 years ago

I'm currently using

.children_signal_vec(signal_of_elements.map(|x| vec![x]).to_signal_vec())

Is there a more efficient way to show a whole tag that comes out of a signal?

thienpow commented 4 years ago

i found a way,


.children(&mut [

                NavBar::render(state.navbar.clone()),

                html!("div", {
                    .style("height", "500px")

                    .children_signal_vec( 
                        Route::signal().map( move |x| 
                            match x {
                                Route::Index => vec![IndexPage::render(state.index_page.clone())],
                                Route::Docs => vec![DocsPage::render(state.docs_page.clone())],
                                Route::Pricing => vec![PricingPage::render(state.pricing_page.clone())],
                                Route::Signup => vec![
                                    SignupPage::render(state.signup_page.clone()),
                                    html!("div", {
                                        .text("Signup!")
                                    })
                                ]
                            }
                        ).to_signal_vec()
                    )
                }),
            ])
Pauan commented 4 years ago

@joonazan Whoops, sorry, somehow I missed your message.

I recently added in a child_signal method, which allows you to attach a single child element (you can return None to remove the child):

.child_signal(signal_of_elements.map(|x| Some(x)))