Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/djgrant/seb

Create stateful components in sites without the luxury of a virtual DOM
https://github.com/djgrant/seb

Last synced: 6 days ago
JSON representation

Create stateful components in sites without the luxury of a virtual DOM

Awesome Lists containing this project

README

        

# SEB

Create reactive components in sites without the luxury of a virtual DOM


Codeship Status for djgrant/seb

SEB is a library for creating components in a browser's actual DOM by facilitating a one way data flow: `Events -> State -> Behaviours`.

Events can only change state, and behaviours in turn respond to state changes. Adaptors allow custom behaviour methods to be made available. For example, the jquery adaptor allows you to use jquery methods declaratively, triggering them as a representation of component's state.

[Examples](https://github.com/djgrant/seb/blob/master/demos/counter/script.js)

A sample counter component:

```js
import SEB from 'seb';
import $ from 'seb-adaptor-jquery';
import classnames from 'seb-adaptor-classnames';

SEB.addAdaptor([$, classnames]);
SEB.createComponent({

self: 'seb-counter',

els: {
button: 'button',
container: '.container',
box: '.box'
},

state: {
ready: false,
count: 0,
angle: -45,
},

events: {
button: {
click: $state => {
$state.set('count', $state.get('count') + 1);
$state.set('angle', $state.get('angle') + 45);
}
}
},

behaviours: {
button: {
html: count => count < 1 ? 'Start Counting!' : 'Incremenent'
},
box: {
html: count => count,
css: (count, angle) => ({
transform: `rotate(${angle}deg)`,
transition: `0.35s transform`
}),
fadeOut: count => count < 1 && 0,
fadeIn: count => count > 0 && { queue: false, duration: 1000 },
animate: count => ({
width: `${count < 8 && count * 30 + 50}`,
height: `${count < 8 && count * 30 + 50}`
}),
},
counter: {
classes: angle => ({
'wide': angle > 90,
'narrow': angle < 90,
'right-angle': angle === 90
})
}
}
});
```