ioof-holdings / redux-subspace

Build decoupled, componentized Redux apps with a single global store
https://ioof-holdings.github.io/redux-subspace/
BSD 3-Clause "New" or "Revised" License
312 stars 33 forks source link

[redux-subspace-saga] Support redux-saga@^1.0.0 #114

Closed TheHolyWaffle closed 5 years ago

TheHolyWaffle commented 5 years ago

Is it a bug, feature request or question?

Bug / feature request?

Which package(s) does this involve?

redux-subspace-saga

Current behavior

redux-subspace-saga does not work with redux-saga v1.

Currently redux-subspace-saga was written to work with redux-saga version 0.16.2. Since then, redux-saga v1 has been released 6 months ago. It appears from local testing that v1 doesn't work with redux-subspace-saga. Downgrading redux-saga to 0.16.2 makes it work again.

TheHolyWaffle commented 5 years ago

From https://github.com/redux-saga/redux-saga/blob/master/CHANGELOG.md it seems that the runSaga API has changed and that the subscribe option is no longer used. See:

TheHolyWaffle commented 5 years ago

Ok, this fixed it:

subspaced.js:

 * Copyright 2017, IOOF Holdings Limited.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree.
 */

import { runSaga, stdChannel } from 'redux-saga'
import { getContext, takeEvery } from 'redux-saga/effects'
import { subspace } from 'redux-subspace'
import provideStore from './provideStore'

const subspaced = (mapState, namespace) => {
  const subspaceDecorator = subspace(mapState, namespace)

  return saga => {
    return function*(...args) {
      const channel = stdChannel()
      const parentStore = yield getContext('store')
      const sagaMiddlewareOptions = yield getContext('sagaMiddlewareOptions')

      const store = {
        ...sagaMiddlewareOptions,
        ...subspaceDecorator(parentStore),
        channel: channel
      }

      runSaga(store, provideStore(store, sagaMiddlewareOptions)(saga), ...args)

      yield takeEvery('*', function*(action) {
        store.processAction(action, channel.put)
        yield
      })
    }
  }
}

export default subspaced
mpeyper commented 5 years ago

Yep, this is part of the larger version upgrade branch I'm currently working on.

https://github.com/mpeyper/redux-subspace/blob/react-redux-v7/packages/redux-subspace-saga/package.json#L39 https://github.com/mpeyper/redux-subspace/blob/react-redux-v7/packages/redux-subspace-saga/src/sagas/subspaced.js

TheHolyWaffle commented 5 years ago

@mpeyper Awesome :) When do you think you'll merge and release? redux-saga v1 is really a must for us

mpeyper commented 5 years ago

Anyone following the upgrade will tell you it's likely going to be too long before it's published. I'd like to give you more reassurance than that, but history is not on my side.

If it helps, I just need to fix the examples and add a few test cases, so it should not be long once I find the time, but I'm doing it out of hours at the moment so I can't make any guarantees.

But it is at the top of my to-do list.