diff --git a/package.json b/package.json index d73ad2f..b590d8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "redux-ignore", - "version": "1.0.1", + "version": "1.1.0", "description": "higher-order reducer to ignore redux actions", "main": "lib/index.js", "scripts": { diff --git a/src/index.js b/src/index.js index 97fe362..af81459 100644 --- a/src/index.js +++ b/src/index.js @@ -1,17 +1,17 @@ -import isFunction from 'lodash/lang/isFunction'; +import isFunction from 'lodash/lang/isFunction' // redux-ignore higher order reducer export default function ignoreActions (reducer, actions = []) { let ignorePredicate = isFunction(actions) ? actions - : (action) => actions.indexOf(action.type) >= 0; + : (action) => actions.indexOf(action.type) >= 0 return (state, action) => { if (!ignorePredicate(action)) { - return reducer(state, action); + return reducer(state, action) } - return state; + return state } } // /redux-ignore diff --git a/test/index.spec.js b/test/index.spec.js index d1456ae..4d9de7d 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -1,52 +1,51 @@ -import assert from 'assert'; -import should from 'should'; -import ignoreActions from '../src/index'; +import assert from 'assert' +import ignoreActions from '../src/index' describe('ignoreActions()', () => { let reducer = (state, action) => { switch (action.type) { case 'FOO': - return 'foo-state'; + return 'foo-state' case 'BAR': - return 'bar-state'; + return 'bar-state' default: - return 'default-state'; + return 'default-state' } - }; + } it('should ignore actions with specified types in array', () => { - let ignoringReducer = ignoreActions(reducer, ['BAR']); - let action = { type: 'BAR' }; + let ignoringReducer = ignoreActions(reducer, ['BAR']) + let action = { type: 'BAR' } assert.equal( ignoringReducer('testing', action), - 'testing'); - }); + 'testing') + }) it('should not ignore actions that do not have types in array', () => { - let ignoringReducer = ignoreActions(reducer, ['BAR']); - let action = { type: 'FOO' }; + let ignoringReducer = ignoreActions(reducer, ['BAR']) + let action = { type: 'FOO' } assert.equal( ignoringReducer('testing', action), - 'foo-state'); - }); + 'foo-state') + }) it('should allow all actions when no action types array is specified', () => { - let ignoringReducer = ignoreActions(reducer); - let action = { type: 'BAZ' }; + let ignoringReducer = ignoreActions(reducer) + let action = { type: 'BAZ' } assert.equal( ignoringReducer('testing', action), - 'default-state'); - }); + 'default-state') + }) it('should work with a predicate function for actions', () => { - let ignoringReducer = ignoreActions(reducer, (a) => a.invalid); - let action = { type: 'BAR', invalid: true }; + let ignoringReducer = ignoreActions(reducer, (a) => a.invalid) + let action = { type: 'BAR', invalid: true } assert.equal( ignoringReducer('testing', action), - 'testing'); - }); -}); \ No newline at end of file + 'testing') + }) +})