# redux-saga-state-machine

> Redux Saga based state machines

Latest version **0.10.8** (published 2018-10-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install redux-saga-state-machine
pnpm add redux-saga-state-machine
yarn add redux-saga-state-machine
bun add redux-saga-state-machine
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.10.8 |
| Published | 2018-10-24 |
| First published | 2018-04-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 64.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Karl O'Keeffe |
| Maintainers | karlokeeffe |

## Links

- npm: https://www.npmjs.com/package/redux-saga-state-machine
- Repository: https://github.com/karl/redux-saga-state-machine
- Homepage: https://github.com/karl/redux-saga-state-machine#readme
- Issues: https://github.com/karl/redux-saga-state-machine/issues
- npm.io page: https://npm.io/package/redux-saga-state-machine

## Recent versions

- 0.10.8 (latest) — 2018-10-24
- 0.10.7 — 2018-10-19
- 0.10.6 — 2018-10-18
- 0.10.5 — 2018-10-12
- 0.10.4 — 2018-10-10
- 0.10.3 — 2018-10-09
- 0.10.2 — 2018-10-02
- 0.10.1 — 2018-09-28
- 0.10.0 — 2018-09-28
- 0.9.0 — 2018-09-24
- 0.8.2 — 2018-09-24
- 0.8.1 — 2018-09-24
- 0.8.0 — 2018-09-21
- 0.7.0 — 2018-09-21
- 0.6.0 — 2018-09-12
- … 14 more at https://npm.io/package/redux-saga-state-machine/versions

## README

![Logo](../resources/logo.png)


# Redux Saga State Machine

**⚠️ A work in progress**

Redux Saga based state machine runner.

## Docs

https://redux-saga-state-machine.netlify.com

## Installing

```
yarn add redux-saga-state-machine
```

You'll also need to install the peer dependencies of Redux, Redux Saga, and xstate (if you haven't already)

```
yarn add redux redux-saga xstate
```

## Using

See a [minimal example on Code Sandbox](https://codesandbox.io/s/github/karl/redux-saga-state-machine/tree/master/examples/minimal)

```js
import { applyMiddleware, createStore } from 'redux';
import createSagaMiddleware from 'redux-saga';
import { createStateMachineSaga } from 'redux-saga-state-machine';

const setStateMachineState = stateMachineState => {
  return { type: 'SET_STATE', payload: stateMachineState };
};
const press = () => {
  return { type: 'PRESS' };
};

const reducer = (state, action) => {
  switch (action.type) {
    case 'SET_STATE':
      return {
        ...state,
        stateMachineState: action.payload,
      };
    default:
      return state;
  }
};

const saga = createStateMachineSaga({
  initial: 'CLOSED',
  setState: setStateMachineState,
  states: {
    CLOSED: {
      on: {
        PRESS: 'OPEN',
      },
    },
    OPEN: {
      on: {
        PRESS: 'CLOSED',
      },
    },
  },
});

const sagaMiddleware = createSagaMiddleware();
const store = createStore(reducer, applyMiddleware(sagaMiddleware));

sagaMiddleware.run(saga, {
  getState: store.getState,
  dispatch: store.dispatch,
});

console.log(store.getState().stateMachineState);
// 'CLOSED'

store.dispatch(press());
console.log(store.getState().stateMachineState);
// 'OPEN'

store.dispatch(press());
console.log(store.getState().stateMachineState);
// 'CLOSED'
```

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