New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design of component children #2

Open
csharad opened this Issue Sep 20, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@csharad
Owner

csharad 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.

@csharad csharad added the design label Sep 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment