0.0.1 • Published 4 years ago

@monoku/reactive-storage v0.0.1

Weekly downloads
8
License
MIT
Repository
github
Last release
4 years ago

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