implement FSA errors by setting error to true if payload is an Error obj#16
Conversation
|
Not sure about this... Feels like it's outside the scope of the module. if the payload is an error, that means someone caught the error and placed it there. Shouldn't it be up to them to set |
|
But there doesn't seem to be a way to set |
|
Oh duh I see what you mean. I was thinking about This seems reasonable then. |
There was a problem hiding this comment.
This check won't work for subclasses of Error (e.g. TypeError)
There was a problem hiding this comment.
Ah thanks, updated to use instanceof.
|
Updated to use instanceof |
|
+1 |
|
+1 |
|
+1, please can you consider releasing this, @acdlite? |
|
+1 |
|
I'm running into this issue now as well. Is this issue expected to be resolved soon? |
|
+1 |
|
I've also had the same issue, I hope it's gonna be released soon! |
There was a problem hiding this comment.
What is the reason for changing this from const to let?
There was a problem hiding this comment.
i guess i didn't have to. thought maybe i should since we modify action below, but we don't reassign.
There was a problem hiding this comment.
To me it's less about the semantics of the keyword and more about consistency with the rest of the code base. const is used whenever a variable does not need to be reassigned.
|
@lukewestby thanks for checking it out, updated. |
|
👍 |
|
@ngokevin export default function createAction(type, actionCreator, metaCreator) {
const finalActionCreator = typeof actionCreator === 'function'
? actionCreator
: identity;
return (...args) => {
const payload = finalActionCreator(...args)
const action = {
type,
payload,
error: (payload instanceof Error)
};
if (typeof metaCreator === 'function') {
action.meta = metaCreator(...args);
}
return action;
};
} |
implement FSA errors by setting error to true if payload is an Error obj
|
Huzzah! I finally got off my ass and merged this! Thanks! |
Noticed this spec of FSA wasn't yet implemented, and there's an issue for it.
This sets action.
errorto true if the payload is a direct instance ofError. This is the faintest touch of magic, but if it's documented, it makes sense.Also fixes a possible error where we're trying to set action.meta even though action is a
const.r? @acdlite