Future-Proof
Web-Components

…and getting beyond complexity

vinyll

Web Developer (2004)
Digital Nomad (2013)

 

Best Practices
Minimalism Maniac

🚂🚋

Web-Components

https://lego.js.org

Isolation & Interchanging

https://lego.js.org

KISS

https://lego.js.org

YAGNI

https://lego.js.org

Freakout 😱

https://lego.js.org

https://github.com/Kinto/kinto-admin/pull/567/

Real World Projects

https://lego.js.org

Crystal Ball

https://lego.js.org

Future-proof?

https://lego.js.org

?

drone.beta.gouv.fr

https://lego.js.org

Sources:

https://framagit.org/drone/raccoon

Extend HTMLElement

https://lego.js.org

class TitleComponent extend HTMLElement {
  constructor() {
    super()
    this.innerHTML = '<h1>This is a component</h1>'
  }
}

customElement.define('x-title', TitleComponent)
<x-title></x-title>

Extend HTMLElement

https://lego.js.org














<!-- x-title.html -->
<template>
  <h1>This is a component</h1>
</template>
<x-title></x-title>

Build Light, Made Native

https://lego.js.org

<template>
  <h1>List of attendees</h1>
  <ul :if="this.attendees.length">
    <li :for="attendee in this.attendees">${ this.attendee.name }</li>
  </ul>
  <p :if="!this.attendees.length">No attendee yet</p>
  
  <button on:click="this.addAttendee">Join!</button>
</template>
  • Template litteral
  • `:if`, `:for`, `on:click`
  • Reactive DOM

So light that You Can Hack

https://lego.js.org

<template>
  <button on:click="this.clicked" :clicked="${ this.state.status === 'clicked' }"><slot></slot> (${ this.state.status })</button>
</template>

<script>
  this.state.status = 'unclicked'

  this.clicked = () => {
    this.state.status = this.state.status === 'unclicked' ? 'clicked' : 'unclicked'
    this.render()
  }
</script>

<style>
  button {
    padding: 1rem 2rem;
    border-radius: .5rem;
    cursor: pointer;
  }
</style>

Compiler is 45 lines

(comments included!)

Compatible

https://lego.js.org

👽

Vincent (aka vinyll)

  • Twitter: @vinyll
  • Mastodon: @vinyll@mastodon.social
  • Email: vinyll@protonmail.com

Lego

  • https://lego.js.org
  • https://github.com/Polight/lego
  • "Decor" and other Polight projects in progress...

Contributions and feedbacks are welcome 🤓

¿Questions?

https://lego.js.org

Future-Proof Web-Components with Lego

By Vincent Agnano

Future-Proof Web-Components with Lego

Web development has been revolutionized with web-components. How can we garantee an app for the future with these technologies?

  • 765