Skip to content

monoku/reactive-storage

Repository files navigation

@monoku/reactive-storage


A reactive storage with zero dependency

Installation

Using npm:

npm install @monoku/reactive-storage --save

Using yarn:

yarn add @monoku/reactive-storage

Using unpkg:

<script src="https://unpkg.com/@monoku/reactive-storage/lib/index.js" />

Basic example:

import ReactiveStorage from '@monoku/reactive-storage';


const MyReactiveStorage = new ReactiveStorage(localStorage); // use localStorage

MyReactiveStorage.setItem('foo', 'bar');

console.log(MyReactiveStorage.getItem('foo'));
// output 'bar'

// Subscribe to 'foo' changes
MyReactiveStorage.subscribe('foo', (event) => {
  console.log(event);
  // output {
  //   key: 'foo',
  //   newValue: 'lorem',
  //   oldValue: 'bar'   
  // }
});

// Set a new value
MyReactiveStorage.setItem('foo', 'lorem');

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published