Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"chai": "^3.0.0",
"eslint": "^0.24.0",
"eslint-config-airbnb": "0.0.6",
"escope": "3.3.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this being used anywhere?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I'm remembering correctly, but I think I needed to add that to bypass an issue with babel-eslint back when redux-actions was on babel 5. I'll remove it now.
estools/escope#99

"lodash.isplainobject": "^3.2.0",
"mocha": "^2.2.5"
},
Expand Down
12 changes: 12 additions & 0 deletions src/__tests__/createAction-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,17 @@ describe('createAction()', () => {
payload: foobar
});
});

it('bypasses action and meta creators if payload is an Error object', () => {
const actionCreator = createAction(type, () => 'not this', () => 'not this either');
const errObj = new TypeError('this is an error');

const errAction = actionCreator(errObj);
expect(errAction).to.deep.equal({
type,
payload: errObj,
error: true
});
});
});
});
11 changes: 5 additions & 6 deletions src/createAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ export default function createAction(type, actionCreator, metaCreator) {
: identity;

return (...args) => {
const hasError = args.length === 1 && args[0] instanceof Error;

const action = {
type,
payload: finalActionCreator(...args)
payload: hasError ? args[0] : finalActionCreator(...args)
};

if (args.length === 1 && args[0] instanceof Error) {
// Handle FSA errors where the payload is an Error object. Set error.
if (hasError) {
action.error = true;
}

if (typeof metaCreator === 'function') {
} else if (typeof metaCreator === 'function') {
action.meta = metaCreator(...args);
}

Expand Down
2 changes: 1 addition & 1 deletion src/handleActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function handleActions(handlers, defaultState) {
const reducers = ownKeys(handlers).map(type => {
return handleAction(type, handlers[type]);
});
const reducer = reduceReducers(...reducers)
const reducer = reduceReducers(...reducers);

return typeof defaultState !== 'undefined'
? (state = defaultState, action) => reducer(state, action)
Expand Down