# state-modules

> A lightweight immutable state management library

Latest version **1.9.0** (published 2019-05-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install state-modules
pnpm add state-modules
yarn add state-modules
bun add state-modules
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.9.0 |
| Published | 2019-05-11 |
| First published | 2018-05-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 100.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Braden R. Napier |
| Maintainers | bradynapier |
| Keywords | state, redux, manager, async, reducer, hooks, components |

## Links

- npm: https://www.npmjs.com/package/state-modules
- Repository: https://github.com/odo-network/state-modules
- Homepage: https://github.com/odo-network/state-modules#readme
- Issues: https://github.com/odo-network/state-modules/issues
- npm.io page: https://npm.io/package/state-modules

## Dependencies (2)

- [immuta](https://npm.io/package/immuta.md) ^1.4.0
- [to-redux-type](https://npm.io/package/to-redux-type.md) ^1.3.1

## Alternatives

- [@reckona/mreact-store](https://npm.io/package/@reckona/mreact-store.md) — 976 weekly downloads
- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [vue-persist-state](https://npm.io/package/vue-persist-state.md) — 19 weekly downloads

## Recent versions

- 1.9.0 (latest) — 2019-05-11
- 1.8.1 — 2018-11-10
- 1.8.0 — 2018-11-10
- 1.7.0 — 2018-11-09
- 1.6.0 — 2018-06-22
- 1.5.2 — 2018-06-19
- 1.5.1 — 2018-06-19
- 1.5.0 — 2018-06-19
- 1.4.0 — 2018-06-17
- 1.3.2 — 2018-06-17
- 1.3.1 — 2018-06-17
- 1.3.0 — 2018-06-17
- 1.1.0 — 2018-06-16
- 1.0.1 — 2018-06-15
- 0.4.0 — 2018-05-27
- … 13 more at https://npm.io/package/state-modules/versions

## README

# State Modules

[![npm](https://img.shields.io/npm/v/state-modules.svg)](https://github.com/odo-network/state-modules)
[![Build Status](https://travis-ci.com/odo-network/state-modules.svg?branch=master)](https://travis-ci.com/odo-network/state-modules)
[![Known Vulnerabilities](https://snyk.io/test/github/odo-network/state-modules/badge.svg?targetFile=package.json)](https://snyk.io/test/github/odo-network/state-modules?targetFile=package.json)
[![Coveralls github](https://img.shields.io/coveralls/github/odo-network/state-modules.svg)](https://github.com/odo-network/state-modules)
[![license](https://img.shields.io/github/license/odo-network/state-modules.svg)](https://github.com/odo-network/state-modules)

State Modules is an immutable state management library allowing the orchestration of your state in an efficient and predictable way. State Modules is largely **reactive** and maintains many powerful models for handling asynchronous scoping in a lazy way.

State Modules use **ES6 Proxies** to capture mutations performed against a "draft state". If changes occur while reducing a dispatched action, updates are dispatched directly to only those components which have subscribed to changes for the given values.

> **Note:** While reducers "appear" to be mutating the state, they are actually mutating an ES6 Proxy. References are then changed based on those mutations so that `nextState !== state` if any values change at any depth within the state.

## Installation

```
yarn add state-modules
```

## Documentation

- [**Reference Documentation**](./docs/reference.md)
- [**Examples**](./docs/examples.md)

## Libraries

- [**react-state-modules**](https://github.com/odo-network/react-state-modules)

## Simple Examples

### State Manager

```javascript
import createState from "state-modules";

const state = createState();

const created = Date.now();

state.component({
  config: { cid: "counter" },
  state: {
    counter: {
      created,
      updated: created,
      value: 0
    }
  },
  selectors: {
    counterValue: "counter.value"
  },
  actions: {
    increment: ["by"],
    decrement: ["by"]
  },
  reducers: {
    INCREMENT(draft, { by = 1 }) {
      draft.counter.value += by;
      draft.counter.updated = Date.now();
    },
    DECREMENT(draft, { by = 1 }) {
      draft.counter.value -= by;
      draft.counter.updated = Date.now();
    }
  }
});

state.actions.increment(5);
state.actions.decrement(1);
state.actions.decrement();

// get the selector 'counterValue' and return results
const currentValue = state.select("counterValue"); // 3
```

---
_Source: https://npm.io/package/state-modules · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
