rbalicki2 / smithy

A framework for building WebAssembly apps in Rust
https://www.smithy.rs
350 stars 10 forks source link

Nested components #9

Open fxdave opened 3 years ago

fxdave commented 3 years ago

Thank you for this crate. It is very useful in our use cases.

Could you please add example of nested components? For example:

   <MyButton>
       Some text
   </MyButton>

I tried something like this:


pub fn render_my_button<'a, 'b>(children: SmithyComponent<'b>) -> SmithyComponent<'a> {
    smd!(
        <button>{ children }</button>
    )
}

// ....

smd!{
    <div>
         { render_my_button(smd!(<div>Increment</div>)) }
         { render_my_button(smd!(<div>Decrement</div>)) }
    </div>
}

I tried with smd_borrowed, but didn't help. I get this error:

[E0277] the trait bound `smithy::types::Node: smithy::types::Component` is not satisfied. 
[Note] the trait `smithy::types::Component` is not implemented for `smithy::types::Node`

Probably I should dig deeper in the code, but asking it is easier.

rbalicki2 commented 3 years ago

Thanks. Adding nested component examples is a good idea.

I'm not off the top of my head 100% certain whether this is supported at the moment. Sorry.

I wish I had a better answer :/