Skip to content
This repository has been archived by the owner on Aug 2, 2020. 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
design Design discussions

Comments

@pepsighan
Copy link
Owner

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 Design discussions label Sep 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
design Design discussions
Projects
None yet
Development

No branches or pull requests

1 participant