paramus

State store for small web applications

Usage no npm install needed!

<script type="module">
  import paramus from 'https://cdn.skypack.dev/paramus';
</script>

README

Tests: CircleCI

Paramus

Paramus is a state store for small web applications, with the goal to work in any stack in with any limitations. The purpose of Paramus is to provide persistent state storage in a none-intrusive way.

For example if your app relies on localstorage, then Paramus can run on the session storage. Or if your app relies on both local- and sessionstorage, then Paramus can run on the url, or in a cookie.

No matter what technologies your app uses, Paramus should be able to find a vacant technology to use for it self.

Demo Fiddle (WIP)

NPM

npm i --save paramus

CDN

<script src="https://unpkg.com/paramus"></script>

API

Paramus(storeId: string, initState: T, onChange?: (state: T) => void): T

import { Paramus } from 'paramus';

/* url | object | <Paramus.extend> + planned "cookie | localStorage |sessionStorage | indexedDB | webSQL"  */
const state = Paramus('url', {
   foo: 3, 
   bar: 42
}, newState => {
   // Triggers whenever a value is changed, ex: state.foo = 7
});

console.log( state.foo ); // 3
state.foo = 7;
console.log( state.foo ); // 7

Adding your own store

Paramus.extend(newStore)

Paramus.extend({
   id: 'object',
   init(initial: object) {
      // Called when a new instance of Paramus is created
      // initial is the state object passed to Paramus
   },
   get(key: string): any {
      // Called whenever a parameter is read from 
   },
   set(key: string, value: any) {
      // Called whenever a parameter is assigned to
   }
});