Skip to content

Commit

Permalink
Merge pull request #4 from oskarhane/store-first
Browse files Browse the repository at this point in the history
Let actions go to store before sending into Suber
  • Loading branch information
oskarhane authored Feb 20, 2017
2 parents 8f6214e + 4813e3e commit c6c79b6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"babel-preset-es2015": "^6.18.0",
"jest-cli": "^18.1.0",
"redux": "^3.6.0",
"redux-mock-store": "^1.2.2",
"redux-observable": "^0.12.2",
"redux-saga": "^0.14.2",
"rxjs": "^5.0.3",
Expand Down
3 changes: 2 additions & 1 deletion src/bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ export function applyMiddleware () {
Array.from(arguments).forEach((arg) => middlewares.push(arg(send)))
}
export const createReduxMiddleware = () => () => (next) => (action) => {
const res = next(action)
bus.send(action.type, action, 'redux')
return next(action)
return res
}
export function applyReduxMiddleware () {
Array.from(arguments).forEach((arg) => {
Expand Down
23 changes: 23 additions & 0 deletions src/redux-compat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'rxjs'
import { createEpicMiddleware } from 'redux-observable'
import createSagaMiddleware from 'redux-saga'
import { put, takeLatest } from 'redux-saga/effects'
import configureMockStore from 'redux-mock-store'

test('can create a redux middleware that repeats all redux actions into bus', () => {
// Given
Expand All @@ -26,6 +27,28 @@ test('can create a redux middleware that repeats all redux actions into bus', ()
expect(cb).toHaveBeenCalledWith(data)
})

test('can create a redux middleware that let actions go to redux store before sending to suber', (done) => {
// Given
const b = getBus()
const channel = 'FROM_MOCK_REDUX'
const data = {id: 10, type: channel}
const mw = createReduxMiddleware()
const mockStore = configureMockStore([mw])
const store = mockStore({
state: {}
})

// When
b.take(channel, (action) => {
// Then
expect(store.getActions()).toEqual([
data
])
done()
})
store.dispatch(data)
})

test('exposes applyReduxMiddleware with same mw signature as redux', () => {
// Given
const b = getBus()
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2575,6 +2575,10 @@ redeyed@~1.0.0:
dependencies:
esprima "~3.0.0"

redux-mock-store@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/redux-mock-store/-/redux-mock-store-1.2.2.tgz#38007dc38f12ca8d965c7521afee5ccacc234d03"

redux-observable@^0.12.2:
version "0.12.2"
resolved "https://registry.yarnpkg.com/redux-observable/-/redux-observable-0.12.2.tgz#4bc1657c7eedace577e114b74ffe6f6fb2b36ccf"
Expand Down

0 comments on commit c6c79b6

Please sign in to comment.