redux-saga / redux-saga-devtools

Saga monitor and UI devtool for redux-saga
MIT License
269 stars 39 forks source link

Custom `dispatch` parameter #7

Closed zalmoxisus closed 7 years ago

zalmoxisus commented 7 years ago

As discussed in #4, it allows to separate the monitor app from watching actions and effects.

So, on the client side we use:

const monitor = createSagaMonitor({ dispatch: (action) => { window.postMessage(action, '*') } })
const sagaMiddleware = createSagaMiddleware({sagaMonitor: monitor})
const store = createStore(
  reducer,
  applyMiddleware(sagaMiddleware)
)
sagaMiddleware.run(rootSaga)

Then on the other side we get actions right in the monitor's store:

const sagaStore = createStore(sagaReducer)
function handleMessages(event) {
  sagaStore.dispatch(event.data)
}
window.addEventListener('message', handleMessages, false)

ReactDOM.render(
  <SagaMonitor monitor={{store: sagaStore}}  />,
  document.getElementById('root')
);
yelouafi commented 7 years ago

thanks!