hetrodoo / observable

An observable pattern implementation in nodejs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

An observable pattern implementation in nodejs


Languages

Language:JavaScript 100.0%