Skip to content
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

Deprecate <content select="..."> in favor of <slot name="..."> #1167

Closed
yyx990803 opened this issue Aug 17, 2015 · 6 comments
Closed

Deprecate <content select="..."> in favor of <slot name="..."> #1167

yyx990803 opened this issue Aug 17, 2015 · 6 comments
Milestone

Comments

@yyx990803
Copy link
Member

Moved from Discussion#298 for tracking in core.

Problem

Context: https://hacks.mozilla.org/2015/06/the-state-of-web-components/ (See the "Distribution" section)

TL;DR: browser vendors cannot agree on the content distribution API for web components. The current <content select="xxx"> syntax will likely be replaced.

The post describes two possible new APIs: an imperative one and a new declarative one. In Vue this has to do with the internal compilation cycle so we are mostly interested in the new declarative API, the "name slots" proposal from Apple:

Component template:

<slot name="header"></slot>
<slot></slot>
<slot name="footer"></slot>
<div>some shadow content</div>

When using the component:

<x-page>
  <header slot="header">header</header>
  <footer slot="footer">footer</footer>
  <h1>my page title</h1>
  <p>my page content<p>
</x-page>

Rendered result:

<x-page>
  <header slot="header">header</header>
  <h1>my page title</h1>
  <p>my page content<p>
  <footer slot="footer">footer</footer>
  <div>some shadow content</div>
</x-page>

The benefits of this proposal over the current <content> API, is that it is much more explicit (the exposed "slots" essentially become part of the component's interface), and thus makes it easier to compose nested components:

<list-item>
  <avatar slot="left-avatar" src="{{user.avatarUrl}}"></avatar>
  <p slot="primary-text">{{user.name}}</p>
  <p slot="secondary-text">{{user.tagline}}</p>
</list-item>

Proposal

Move to the <slot> API. It's more explicit than <content> select. This could co-exist with <content> in 1.0.0-alpha.

@azamat-sharapov
Copy link

Looks great. How will this behave if you add inline-template to component (to <x-page> or <list-item>)?

@yyx990803
Copy link
Member Author

inline-template is exclusive with content insertion, so adding it makes no sense here.

@yyx990803 yyx990803 modified the milestone: 1.0.0-alpha Aug 17, 2015
@azamat-sharapov
Copy link

I see. So, here:

<list-item>
  <avatar slot="left-avatar" src="{{user.avatarUrl}}"></avatar>
</list-item>

<list-item> and <avatar> are compiled under same context?

@yyx990803
Copy link
Member Author

Yes, but <avatar> will be considered a child of <list-item>.

@dgerber
Copy link

dgerber commented Aug 25, 2015

Could slot support a way to be compiled in local scope, while inheriting assets from the consumer?

Take a grid component exposing customizable cells. With #1170, one must either name a partial (or component) globally to use it in the cell, or use the grid component as a mixin.

The grid template would look like this:

<tr v-for="row in rows">
  <td v-for="col in columns">
    <slot name="cell" scope="local" inherit-assets="true"></slot>
  </td>
</tr>

Usage:

<parent>
  <grid>
    <div slot="cell">
      In {{row}}, {{col}}:
      <some-component-from-parent/>
    </div>
  </grid>
</parent>

@yyx990803
Copy link
Member Author

implemented in alpha branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants