saphir

Observable objects

Usage no npm install needed!

<script type="module">
  import saphir from 'https://cdn.skypack.dev/saphir';
</script>

README

Saphir Build Status Coverage Status

A small library that helps to observe defined Object/Array properties.

npm install saphir
# or
bower install saphir
var observableObj = new SaphirObject(
  {a: 'foo'}
);

observableObj._subscribe('a', function(newValue, oldValue) {
  console.log(oldValue + ' => ' + newValue);
});

observableObj.a = 'bar';
// foo => bar

var observableArr = new SaphirArray([1, 3, 2]);

observableArr._subscribe(function(newValue) {
  console.log(newValue);
});

observableArr[0] = 4;
// [4, 3, 2]
observableArr.push(1);
// [4, 2, 3, 1]

TODO

  • multi subscription
  • more benchmarks