1.2.0 • Published 4 years ago

state-containers v1.2.0

Weekly downloads
2
License
Unlicense
Repository
github
Last release
4 years ago

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.

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago