@polight/lego
Version:
Tiny Web Components lib for future-proof HTML mentors
60 lines (43 loc) β’ 3.94 kB
Markdown
---
title: Welcome
weight: 1
---
LEGO (_Lightweight Embedded Gluten-free Objects_) is a library for writing fast {{< emoji "β»οΈ" >}} reactive, {{< emoji "π¦" >}} scoped and predictable {{< emoji "π‘" >}} **native Web Components** in HTML/CSS/JS, that are easy to digest {{< emoji "π±" >}} for your browser.
Example (`bricks/my-example.html`):
```html
<template>
<h1>Welcome to LEGO</h1>
<p>The lean way to make ${state.duration} Web Components powerful and easy</p>
</template>
<script>
export default class extends Lego {
state = { duration: 'Future-Proof' }
}
</script>
<style>
p {
color: chocolate;
}
</style>
```
These are **native HTML elements** with [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM), slots and all native features from the official specs.
LEGO is:
- {{< emoji "π" >}} Minimalist: 117 lines of readable code in its core (non-optimized, uncompressed, no cheating);
- {{< emoji "π±" >}} Low dependency: its single third-party is the **minimalist** [petit-dom](https://github.com/yelouafi/petit-dom) which is stable and embedded, and which itself has no dependency. So no bad surprise in the future;
- {{< emoji "β»οΈ" >}} Reactive: updating the state recalculate the [Virtual DOM](https://en.wikipedia.org/wiki/Virtual_DOM) when needed;
- {{< emoji "π" >}} Fast: using Virtual DOM through a thin layer makes it close to bare-metal;
- {{< emoji "π§" >}} Simple: that's [VanillaJS](http://vanilla-js.com/)! There isn't much to know, it's a raw class to extend. No magic {{< emoji "β¨" >}};
- {{< emoji "πͺΆ" >}} 3 directives to enhance HTML: `:if` for conditions, `:for` for loops, `@myfuncname` to call an action;
- {{< emoji "π‘" >}} Native: LEGO components are actual native Web Components. You benefit from all the today's and tomorrow's possibilities ([slot](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_templates_and_slots), [encapsulation with Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM), β¦);
- {{< emoji "π¦Ί" >}} Safe: because it has no third-party dependency and is fully based on browser features, it's secured and upgraded via your browser.
LEGO is not (and will never be):
- {{< emoji "π―" >}} A fully-bloated front-end framework with built-in routing. [Others do it well](https://github.com/visionmedia/page.js);
- {{< emoji "π" >}} A website builder with built-in SSR or similar complexities;
- {{< emoji "π" >}} An HTML replacement that locks you into a specific technology;
- {{< emoji "π§" >}} An old browsers or IE compatible library. [Support for _Custom Elements_ is spreading](https://caniuse.com/#feat=custom-elementsv1) and shall increase in time (you may try [Web Components polyfills](https://github.com/webcomponents/polyfills) if you feel wild).
## Next Steps, Demo and Doc
{{< emoji "π§ͺ" >}} View the [demo](https://polight.github.io/lego-demo/) and [their source](https://github.com/Polight/lego-demo).
{{< emoji "π" >}} LEGO is inspired from the [native Web Component specs](https://developer.mozilla.org/en-US/docs/Web/Web_Components) and [Riot](https://riot.js.org/).
{{< emoji "π§" >}} Customizing and contributing is just **much lighter** with simplicity. Source are easy to read for a regular developer which makes it accessible to maintain, to [tweak and to hack]({{< relref "extending" >}}) in the *loooong* term.
{{< emoji "π" >}} You can [read the core code](https://github.com/Polight/lego/blob/master/src/lib/Component.js)! That is only 117 <abbr title="Lines Of Code">LOC</abbr> resulting that LEGO is **as light as 2.8KB** for the full bundle! No Babel transpiler, no Parcel, no Webpackβ¦ It just works out of the box.
{{< emoji "π">}} Keep on reading this documentation and start writing your first LEGO componentβ¦