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

improve how to generate dynamic slot content in the carousel #2

Open
thescientist13 opened this issue May 30, 2018 · 0 comments
Open
Labels
good first issue Good for newcomers

Comments

@thescientist13
Copy link
Member

currently the carousel component needs to know how many slots are being provided in order to dynamically bind everything together.

<pe-carousel slots$=${this.content.length}>
  ${ this.content.map(this.generateSlotTemplate) }
</pe-carousel>
generateCarouselContent() {
  return new Array(this.slots).fill(null).map((item, index) => {
    const isActiveSlot = index === this.activeIndex ? 'active-slot' : 'slot';

    return html`
      <div class$="${isActiveSlot}"><slot name$="slide${index + 1}"></slot>
    `;
  });
}

Not sure if there would be any performance issues query for number of <slot> elements internally within the component itself instead, i.e.

generateCarouselContent() {
  const slots = this.$('slot');

  return slots.length.map((item, index) => {
    const isActiveSlot = index === this.activeIndex ? 'active-slot' : 'slot';

    return html`
      <div class$="${isActiveSlot}"><slot name$="slide${index + 1}"></slot>
    `;
  });
}
@thescientist13 thescientist13 added the good first issue Good for newcomers label May 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant