mechanical-elements
v0.7.5
Published
Template Engine for WebComponents
Downloads
5
Maintainers
Readme
MechanicalElements
MechanicalElements is a superset of ActuatorElements. If boundData have the same API as EventEmitter(more precisely, emit, addListener/on, removeListener/off), MechnicalElements can detect data changes and reflect them in the view.
Installing
$ npm install --save mechanical-elements
$ bower install --save mechanical-elements
Examples
const EventEmitter = require('events').EventEmitter;
class TodoListModel extends EventEmitter {
constructor(todos=[]) {
this._todos = todos;
}
add(todo) {
this._todos.push(todo);
this.emit('splice', this._todos.length, 0, 1); // event type, index, removedCount, addedCount
}
}
class TodoModel extends EventEmitter {
constructor(title, completed) {
super();
this.title = title;
this.completed = completed;
}
set(name, value) {
this[name] = value;
this.emit('update', name);
}
get(name) {
return this[name];
}
}
Or you can use sensor-objects.
const sensors = require('sensor-objects');
const todo = new sensors.Object({
title: 'title'
});
// or
class TodoModel extends sensors.Object {
constructor(title, completed) {
super({ title, completed });
}
}