This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@mathias_frost/simplestores
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Simple Stores

Minimal framework-independent stores

Example:

Creating a store

import {LocalStore, SessionStore, Store} from '@mathias_frost/simplestores';

export interface SomeModel {
  someString: string;
  someNumber: number;
  someBool: boolean;
}

export const store = new Store<SomeModel>({someString: 'string', someNumber: 6, someBool: true});
export const sessionStore = new SessionStore<SomeModel>({someString: 'string', someNumber: 6, someBool: true}, 'some_key');
export const localStore = new LocalStore<SomeModel>({someString: 'string', someNumber: 6, someBool: true}, 'some_key');

Subscribing (React)

import React from 'react';
import {localStore, sessionStore, store} from './stores';
import type {Subscribe} from '@mathias_frost/simplestores';

export class Component extends React.Component<{}, {}> {

  /** Store event as to unsubscrube at unmount (not required) */
  store: Subscribe<SomeModel> | null = null;

  componentDidMount() {
    this.store = store.subscribe((value: SomeModel) => this.setState({store: value}));
  }

  componentWillUnmount() {
    store.unsubscribe(this.store);
  }
}

Unsubscribing is optional but recommended

Set value

import {store} from './stores';

store.value = "New value";

This will update subscribers

Get value

import {store} from './stores';

const value = store.value;

This will fetch the actual value possibly stored in session or local storage

Readme

Keywords

none

Package Sidebar

Install

npm i @mathias_frost/simplestores

Weekly Downloads

2

Version

1.0.5

License

MIT

Unpacked Size

78.9 kB

Total Files

24

Last publish

Collaborators

  • mathias_frost