Skip to content

💡 A simple Observable implementation for JavaScript/TypeScript. Allowing you to observe a value and get notified whenever it is changed.

Notifications You must be signed in to change notification settings

dobschal/observable

Repository files navigation

Observable

A simple Observable implementation in JavaScript.

Test NPM

Installation

npm install --save @dobschal/observable

Usage

Observe values and get notified when they change:

import { Observable } from '@dobschal/observable';

const count = Observable(5);

count.subscribe(value => {
  console.log(value);
});

count.set(10); // will trigger the subscription and log 10
count.value = 15; // will trigger the subscription and log 15

Watch computed values:

import { Computed, Observable } from '@dobschal/observable';

const count = Observable(5);
const multiplied = Computed(() => count.value * 2);

multiplied.subscribe(value => {
  console.log(value);
});

About

💡 A simple Observable implementation for JavaScript/TypeScript. Allowing you to observe a value and get notified whenever it is changed.

Topics

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •