0.1.4 • Published 6 years ago

redux-xstate v0.1.4

Weekly downloads
8
License
MIT
Repository
github
Last release
6 years ago

redux-xstate

Redux middleware for xstate

Installation

$ npm install redux-xstate

Usage

import { createMiddleware, createReducer } from 'redux-xstate'

const actionMap = {
  log: (dispatch, state) => fetch(LOG_URL, {
    method: "POST",
    body: JSON.stringify(state)
  })
}
const stateChart = {
  key: "light",
  initial: "green",
  states: {
    green: {
      on: {
        TIMER: "yellow"
      }
    },
    yellow: {
      on: {
        TIMER: "red"
      }
    },
    red: {
      on: {
        TIMER: "green"
      },
      onEntry: ["log"]
    }
  }
}

const machine = Machine(stateChart)

const store = createStore(
  combineReducers({
    machine: createReducer(machine.initialState)
  }),
  applyMiddleware(createMiddleware(machine, actionMap))
)

store.dispatch("TIMER")

// state.machine.value === "yellow"

License

MIT

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago