Mental Model Simplicity
No virtual DOM, no compilation step, no JSX. Just HTML with a few directives and reactive objects.
A tiny, zero-dependency Web library for creating reactive Web Components directly in the browser
How you name your blocks depends on how you use LegoDOM:
Convention over Configuration. The filename is the tag name.
user-card.lego → <user-card></user-card>app-nav.lego → <app-nav></app-nav>You do not need b-id inside .lego files; the build system handles registration automatically.
Since there are no files, you must explicitly name your blocks using the b-id attribute on the <template> tag.
<!-- Only needed for CDN usage -->
<template b-id="user-profile">
<h1>User Profile</h1>
</template><!-- Define a block -->
<template b-id="counter-button" b-logic="{
title: 'My counter',
count: 0
}">
<style>
self {
display: block;
padding: 1rem;
}
button {
font-size: 1.2rem;
padding: 0.5rem 1rem;
}
</style>
<h2>[[ title ]]</h2>
<button @click="count++">
Clicked [[ count ]] times
</button>
</template>
<!-- Use it -->
<counter-button b-logic="{ title: 'Override b-logic title' }"></counter-button>
<script src="https://unpkg.com/lego-dom/main.js"></script>
<script>
// Complete the initialization
Lego.init();
</script>That's it. No build step, no npm, no configuration.
IMPORTANT
Why call Lego.init()? While Lego.block() (or simple templates) will "snap" your blocks into the page immediately, you must call Lego.init() to start the background engine. Without it:
[[...]]) outside of blocks won't hydrate.For small projects, you get reactive blocks without the overhead of a full framework.
For large projects, you get a clear mental model and Web Standards compliance.
For learning, you can read the entire source code in an afternoon and understand exactly how it works.
| Feature | LegoDOM | Vue | React |
|---|---|---|---|
| Size | < 17KB | ~33KB | ~40KB |
| Dependencies | 0 | Many | Many |
| Build Required | No* | Yes | Yes |
| Virtual DOM | No | Yes | Yes |
| Learning Curve | Minimal | Moderate | Moderate |
| Web Components | Native | Optional | No |
* Optional with Vite for .lego files
LegoDOM works in all modern browsers that support:
This includes Chrome 63+, Firefox 63+, Safari 11.1+, and Edge 79+.