Currently in heavy development (learning project). Do not use in production.
Lucia is a tiny JavaScript library for web applications.
- Declarative: Lucia makes it painless to create interactive UIs. Declarative views make your code more predictable, simpler to understand, and easier to debug.
- Reactive: When a data point is changed, the loose Virtual DOM will react and will update and render the points in realtime.
- Data-Driven: Instead of using traditional direct DOM manipulation, Lucia provides an interface to change data to mutate our loose Virtual DOM.
Installation
Put this within your <head>
tags in html.
<script src="https://unpkg.com/lucia/dist/lucia.js"></script>
<script src="https://unpkg.com/lucia"></script>
Example
Below is an example of a clicker game in Lucia. Try it out live here: https://luciaclickergame.aidenbai.repl.co.
<div id="app">
<button l-on:click="increment()">{{ count }}</button>
</div>
const ClickerGame = {
data: {
count: localStorage.count || 0,
increment() {
localStorage.count = ++this.count;
},
},
};
Lucia.createApp(ClickerGame).mount('#app');
Features
Declarative Rendering
At the core of Lucia is a system that enables us to declaratively render data to the DOM using straightforward template syntax:
<div id="app">
<p>{{ message }}</p>
<p>{{ message === 'Hello World!' }}</p>
</div>
const App = {
data: {
message: 'Hello World!',
},
};
Lucia.createApp(App).mount('#app');
You can also use the l-html
directive for more advanced content manipulation.
<div id="app">
<p l-html="message"></p>
</div>
const App = {
data: {
message: '<button>Hello World!</button>',
},
};
Lucia.createApp(App).mount('#app');
Conditionals
It’s easy to toggle the presence of an element, too:
<div id="app">
<button l-if="show">You can't see me</button>
<button l-if="!show">You can see me</button>
</div>
const App = {
data: {
show: false,
},
};
Lucia.createApp(App).mount('#app');
Event Handlers
To let users interact with your app, we can use the l-on
directive to attach event listeners that invoke methods on our Lucia instances:
<div id="app">
<button l-on:click="announce()">{{ message }}</button>
</div>
const App = {
data: {
message: 'Hello world!',
announce() {
alert(this.message);
},
},
};
Lucia.createApp(App).mount('#app');
Attribute Binding
In addition to text interpolation, we can also bind element attributes like this:
<div id="app">
<h1 l-bind:class="{ hello: show }">Classes are cool</h1>
<h1 l-bind:style="color">Styles are sassy</h1>
</div>
const App = {
data: {
show: true,
color: { color: 'purple' },
},
};
Lucia.createApp(App).mount('#app');
List Rendering
We can use the l-for directive to render a list of items based on an array.
<div id="app">
<p l-for="fruits by , "></p>
</div>
const App = {
data: {
fruits: ['apple', 'orange', 'banana'],
},
};
Lucia.createApp(App).mount('#app');
Form Input Bindings
You can use the l-model directive to create two-way data bindings on form input, textarea, and select elements.
<div id="app">
<input l-model="content" />
{{ content }}
</div>
const App = {
data: {
content: 'Nothing submitted yet',
},
};
Lucia.createApp(App).mount('#app');
License
Lucia is MIT licensed.