Skip to content
/ elch Public

Tiny reactive templates with zero dependencies 🐴

License

Notifications You must be signed in to change notification settings

pauwell/elch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

elch

Features

🔥 Simple

🔥 Small (~15kb)

🔥 Independent

Setup

git clone https://github.com/pauwell/elch.git

  • npm install
  • npm run build

Example

const myTemplate = new Elch({
  name: 'counter-example',
  state: { count: 0 },
  logic: {
    incrementCount() {
      this.count += 1;
    }
  },
  view: () =>
    `<div class="counter-app">
        <h1>Counter</h1>
        <p>Current value: {{count}}</p>
        <button do-event="click:incrementCount">Click</button>
    </div>`
});

myTemplate.mountTo(document.getElementById('app'));

If-conditions

<do if="this.state.count > 10">
  <p>Visible if count is greater than ten.</p>
</do>

For-loops

<do for="let i=0; i<this.state.count; ++i">
  <p>{{ $i }}</p>
</do>

Event-attributes

<button do-event="click:incrementCount">Click</button>

Nested templates

<div class="other-template">
  <counter-app></counter-app>
</div>

About

Tiny reactive templates with zero dependencies 🐴

Resources

License

Stars

Watchers

Forks

Packages

No packages published