@hetrodo/observable
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Observable Logo

Downloads

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

Package Sidebar

Install

npm i @hetrodo/observable

Weekly Downloads

3

Version

1.1.1

License

MIT

Unpacked Size

3.95 kB

Total Files

4

Last publish

Collaborators

  • hetrodo