JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8
  • Score
    100M100P100Q60051F
  • License ISC

@webkrafters/universal-storage package dx friend wrapper

Package Exports

  • universal-storage
  • universal-storage/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (universal-storage) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Universal Storage

A persistent client-server coordinated storage based on client domain cookies with a local-storage fallback.

Name:

universal-storage

Installation

npm install --save universal-storage

Usage

In client-side code.

import { discardClientStorage, getClientStorage } from 'universal-storage';

let storage = getClientStorage(); // establishes a client storage singleton

storage.current.setItem( 'key', 'value' );
storage.current.getItem( 'key' ); // 'value'
storage.current.removeItem( 'key' );

storage.current.getItem( 'key' ); // undefined
storage.current.setItem( 'key', 'value2' );
storage.current.getItem( 'key' ); // 'value2'

discardClientStorage(); // destroys the current client storage singleton

storage.current.getItem( 'key' ); // error! cannot read getItem of undefined; reading 'storage.current'

storage = getClientStorage(); // reestablishes a client storage singleton

storage.current.getItem( 'key' ); // 'value2' 

In server-side code.

import { discardServerStorage, getServerStorage } from 'universal-storage';

let storage = getServerStorage(); // establishes a client storage singleton

storage.current.setItem( 'key', 'value', e.response );
storage.current.getItem( 'key', e.request ); // 'value'
storage.current.removeItem( 'key', 'value', e.response );

storage.current.getItem( 'key', e.request ); // undefined
storage.current.setItem( 'key', 'value2', e.response );
storage.current.getItem( 'key', e.request ); // 'value2'

discardServerStorage(); // destroys the current client storage singleton

storage.current.getItem( 'key', e.request ); // error! cannot read getItem of undefined; reading 'storage.current'

storage = getServerStorage(); // reestablishes a client storage singleton

storage.current.getItem( 'key', e.request ); // 'value2' 

License

MIT