0.0.31 • Published 7 years ago

redux-go-workflows v0.0.31

Weekly downloads
4
License
Apache-2.0
Repository
github
Last release
7 years ago

redux-go-channels

Simple redux middleware for js-go-channels.

Installation

npm install js-go-channels
npm install redux-go-channels

Usage

Create a workflow.

// workflow.js
export function workflow({getState, dispatch, take}) {
  return function*() {
    for(;;) {
      // wait for ACTION
      const {payload} = yield take('ACTION')
      // get current state
      const state = getState()
      // do something with payload and state
      const result = //...
      // dispatch an action
      dispatch({type: 'RESULT', payload: result})
      // wait for the next ACTION
    }
  }
}

Register the workflow.

import {createStore, applyMiddleware} from 'redux'
import {createMiddleware} from 'redux-go-workflows'

import reducer from './reducers' // created as you normally would
import workflow from './workflow' // defined above

// create the workflow middleware
const {register, middleware} = createMiddleware()
// mount it on the Store
const store = createStore(
  reducer,
  applyMiddleware(middleware)
)

// register workflow
register([workflow])

That's it!

You can think of a workflow as an (optionally) long-running process. It's inspired by redux-thunk and redux-saga with several differences:

  • communication with a workflow is possible only by dispatching messages (whatever it takes). This preserves replayability.
  • workflows can only query the store state (getState), dispatch messages, and wait for specific messages (take). That's it! No complicated API.
0.0.31

7 years ago

0.0.30

7 years ago

0.0.29

7 years ago

0.0.28

7 years ago

0.0.27

7 years ago

0.0.26

7 years ago

0.0.25

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago