salsita / prism

React / Redux action composition made simple http://salsita.github.io/prism/
496 stars 24 forks source link

Applying Store Middleware #31

Closed jmatsushita closed 8 years ago

jmatsushita commented 8 years ago

Hi there,

I'm giving redux-elm a spin and I was wondering if it's possible to add store middleware?

I've tried this to modify the boilerplate.js file with https://github.com/pgte/pouch-redux-middleware:

  const db = new PouchDB('todos');

  const pouchMiddleware = PouchMiddleware({
    path: '/todos',
    db,
    actions: {
      remove: doc => store.dispatch({type: types.DELETE_TODO, id: doc._id}),
      insert: doc => store.dispatch({type: types.INSERT_TODO, todo: doc}),
      update: doc => store.dispatch({type: types.UPDATE_TODO, todo: doc}),
    }
  })

  const storeFactory = compose(
    reduxElm,
    applyMiddleware(pouchMiddleware),
    window.devToolsExtension ? window.devToolsExtension() : f => f
  )(createStore);

  const store = storeFactory(updater);

But it doesn't seem to work.

I'm probably missing something trivial?

Thanks for your time!

Jun

eliperelman commented 8 years ago

@jmatsushita I'm not sure if I've done it the correct way or if there will be side-effects from doing it this way, but I used the following:

const store = createStore(
  combineReducers({ root: updater, routing: routerReducer }),
  compose(
    reduxElm,
    applyMiddleware(createLogger()),
    instrument,
    persist
  )
);
tomkis commented 8 years ago

@jmatsushita I tried your example and it seemed to be working except there was of course some missing imports which had to be resolved.

Can you please elaborate on what you mean by "it doesn't seem to work"?

jmatsushita commented 8 years ago

It all works (apart from my initial understanding of how it should work ;))