0.10.8 • Published 6 years ago
redux-saga-state-machine v0.10.8
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
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'
0.10.8
6 years ago
0.10.7
6 years ago
0.10.6
6 years ago
0.10.5
6 years ago
0.10.4
6 years ago
0.10.3
6 years ago
0.10.2
6 years ago
0.10.1
6 years ago
0.10.0
6 years ago
0.9.0
6 years ago
0.8.2
6 years ago
0.8.1
6 years ago
0.8.0
6 years ago
0.7.0
6 years ago
0.6.0
6 years ago
0.5.1
6 years ago
0.5.0
6 years ago
0.4.2
6 years ago
0.4.0
6 years ago
0.3.0
6 years ago
0.2.0
6 years ago
0.1.18
6 years ago
0.1.0
6 years ago
0.0.8
6 years ago
0.0.7
6 years ago
0.0.5
6 years ago
0.0.4
6 years ago
0.0.3
6 years ago
0.0.2
6 years ago