@hetrodo/observable
v1.1.1
Published
An observable pattern implementation in nodejs
Downloads
4
Maintainers
Readme
Observable is a simple and lightweight implementation of the observable pattern in nodejs, it fires events when properties are changed.
But note that only the root properties of objects are observed.
Supported types
Object
Array
Primitives
(string, number, boolean, null, undefined)
Installation
npm install @hetrodo/observable
Usage
const Observable = require("@hetrodo/observable");
const counter = new Observable(0); //Create a new observable with the initial value of 0
counter.subscribe((value) => {
console.log(value); //Subscribe to the observable, this will print the value of the observable every time it changes
});
setInterval(() => {
counter.value++; //Increment the value of the observable every second
}, 1000);