Create an on-demand mirror of a flyd datastructure
A small (0.8 kB min+gzip) module for flyd
that can generate mirrors and images, useful when you want to combine
reactive programming with plain old JavaScript objects.
``bash`
npm install flyd-mirror
image is mirroring streams...
`javascript`
var data = {
name: flyd.stream("Fry"),
age: flyd.stream(1023)
};
var image = fm.image(data);
assert.equal(image.name(), "Fry");
assert.equal(image.age(), 1023);
...while mirror is listening to these images...
`javascript``
var sq = fm.mirror(function() {
return image.age()*image.age();
});
assert.equal(sq(), 1046529);
data.age(1024); // happy birthday!
assert.equal(sq(), 1048576);
making it possible for the mirror to automatically update when the underlying streams are updated.