Skip to content

A tiny front-end framework that lets dom elements listen to changing state.

Notifications You must be signed in to change notification settings

MarkSchu/element-ears

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Element Ears

A library that hooks up DOM elements to state changes.

Hello World

There are two basic ways to bind elements to state.

bind attribute

Create an element and pass it a handler that change its properties. Below, when foo changes, handleFoo is called.

import { ObservableVar, element } from 'element-ears';

const HelloEl = () => {

    const foo = new ObservableVar(0);

    const handleFoo = (el, value) => {
        el.textContent = value;
    }

    return (
        element('div', {
            bind: [[foo, handleFoo]]
        })
    )
}

bind function

Create an element and pass it a callback that sets its children. Below, when foo changes, the callback sets the span as the child of the div.

import { ObservableVar, bind, element } from 'element-ears';

const WorldEl = () => {

    const foo = new ObservableVar(0);

    return (
        bind('div', {}, foo, (value) =>
            element('span', {textContent: value})
        )
    )
}

About

A tiny front-end framework that lets dom elements listen to changing state.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published