Skip to content

Commit

Permalink
Merge branch 'undefined-initial-state' of https://github.com/maxmecha…
Browse files Browse the repository at this point in the history
…nic/redux-ignore into maxmechanic-undefined-initial-state
  • Loading branch information
omnidan committed Aug 19, 2016
2 parents 4db3331 + d2b2356 commit ce77141
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ function createActionHandler (ignore) {
? actions
: (action) => actions.indexOf(action.type) >= 0

return (state, action) => {
const initialState = reducer(undefined, {})

return (state = initialState, action) => {
if (predicate(action)) {
return ignore ? state : reducer(state, action)
}
Expand Down
11 changes: 11 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import assert from 'assert'
import { createStore } from 'redux'

import { ignoreActions, filterActions } from '../src/index'

let reducer = (state, action) => {
Expand Down Expand Up @@ -86,4 +88,13 @@ describe('filterActions()', () => {
filteringReducer('testing', action),
'bar-state')
})

it('should return an initial state when a redux store is created', () => {
let filteringReducer = filterActions(reducer, ['BAR'])
let store = createStore(filteringReducer)

assert.equal(
store.getState(),
reducer(undefined, {}))
})
})

0 comments on commit ce77141

Please sign in to comment.