-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
type, | ||
payload: finalActionCreator(...args) | ||
}; | ||
|
||
if (typeof metaCreator === 'function') action.meta = metaCreator(...args); | ||
if (args.length === 1 && args[0].constructor === Error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check won't work for subclasses of Error (e.g. TypeError)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah thanks, updated to use instanceof
.
Updated to use instanceof |
+1 |
+1 |
2 similar comments
+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! |
@@ -8,12 +8,19 @@ export default function createAction(type, actionCreator, metaCreator) { | |||
: identity; | |||
|
|||
return (...args) => { | |||
const action = { | |||
let action = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for changing this from const
to let
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
error
to 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