0.7.5 • Published 8 years ago

mechanical-elements v0.7.5

Weekly downloads
-
License
MIT
Repository
-
Last release
8 years ago

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 });
  }
}
0.7.5

8 years ago

0.7.4

8 years ago

0.7.3

8 years ago

0.7.2

8 years ago

0.7.1

8 years ago

0.7.0

8 years ago

0.6.11

8 years ago

0.6.10

8 years ago

0.6.9

8 years ago

0.6.8

8 years ago

0.6.7

8 years ago

0.6.6

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.1

8 years ago