Skip to content
This repository has been archived by the owner. It is now read-only.

Design of component children #2

Open
pepsighan opened this issue Sep 20, 2018 · 0 comments
Open

Design of component children #2

pepsighan opened this issue Sep 20, 2018 · 0 comments
Labels

Comments

@pepsighan
Copy link
Owner

@pepsighan pepsighan commented Sep 20, 2018

Currently component children is not supported. The target design which I am striving for here is inspired/taken from vuejs (slot system).
The design demands the following requirements:

  1. The slots are rendered in the context where it is written. The fields & methods of the component is accessible to the slot but not of the child component.
...
struct MyApp { ... }

impl MyApp {
  fn on_click(&self, _: Event) {}
}

impl Render for MyApp {
  fn render(&self) -> Markup<Self> {
    html! {
      <Content>
        { self.prop_a }
        <button @click={Self::on_click}>Click</button>
        // But cannot access Content.do_something
      </Content>
    }
  }
}

...
struct Content { ... }

impl Content {
  fn do_something(&self) {}
}

impl Render for Content {
  fn render(&self) -> Markup<Self> {
    html! {
      <div>
        <slot></slot>
      </div>
    }
  }
}
  1. Slots are functional which accept arguments from their children aka Scoped Slots.

  2. There can be any number of named slots.

@pepsighan pepsighan added the design label Sep 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant