easy-peasy icon indicating copy to clipboard operation
easy-peasy copied to clipboard

thunk completeType not called on fail

Open joelmoss opened this issue 3 years ago • 5 comments

It appears that a failed thunk does not trigger the complete action type.

So a saveTodo thunk should always trigger listeners for saveTodo.type, which it does so for a successful thunk, but not a failed thunk.

joelmoss avatar Oct 15 '20 09:10 joelmoss

Full response in the works. :)

ctrlplusb avatar Oct 16 '20 10:10 ctrlplusb

With v4+, to trigger the fail action on a failed thunk, you need to call the fail() function, which is passed on the helpers object but was not mentioned in the docs. I have opened two PRs to both add it to the Helpers Typescript type definition as well as document its usage in the api/thunks docs:

#572 #574

@ctrlplusb hope this is helpful! =)

RobvH avatar Oct 16 '20 16:10 RobvH

Yes I know, but the type action still doesn't get called either way. Which it always should, no matter if it succeeded or failed, as it still completed.

joelmoss avatar Oct 16 '20 16:10 joelmoss

Apologies, I'm afraid I misread your initial statement. Sean clearly understands, but it might benefit others to have a little more information. Looking from the docs inward, I'm unaware of a type action existing or being expected.

RobvH avatar Oct 16 '20 17:10 RobvH

When I say the type action, I mean the default action. Take a look at https://easy-peasy.now.sh/docs/api/listeners.html#thunkon

...actions => actions.addTodo

Then with thunks, you also have the start, success and fail actions:

...actions => actions.saveTodo.successType

joelmoss avatar Oct 16 '20 17:10 joelmoss