state-containers
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

state-containers

  • Strongly typed state containers with TypeScript.
  • Redux-like but without the boilerplate.
  • Simple state management for your services and React apps.
  • Composable: use just state containers, or with React helpers or add optional routines to the mix.

Usage

Install

npm install state-containers

Use

import {StateContainer, PureTransition, createStateContainer} from 'state-containers';
 
type CounterState = number;
 
interface CounterPureTransitions {
  increment: PureTransition<CounterState, [number]>;
  double: PureTransition<CounterState, []>;
  setTo: PureTransition<CounterState, [number]>;
}
 
const defaultState: CounterState = 0;
 
const pureTransitions: CounterPureTransitions = {
  increment: cnt => by => cnt + by,
  double: cnt => () => 2 * cnt,
  setTo: ctn => to => to,
};
 
const store = createStateContainer(defaultState, pureTransitions);
 
store.transitions.increment(5);
store.transitions.double();
store.state; // 10

Reference

Examples

License

Unlicense — public domain.

Readme

Keywords

none

Package Sidebar

Install

npm i state-containers

Weekly Downloads

4

Version

1.2.0

License

Unlicense

Unpacked Size

20.1 kB

Total Files

18

Last publish

Collaborators

  • streamich