Skip to content
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

Handler map factory should handle optimistic action type #4

Open
the-dr-lazy opened this issue Jan 20, 2019 · 4 comments
Open

Handler map factory should handle optimistic action type #4

the-dr-lazy opened this issue Jan 20, 2019 · 4 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@the-dr-lazy
Copy link
Owner

According to #2, createHandlerMap should be capable to handle optimistic action creators.

Detailed Description

Yet, optimistic actions should be handled separately with multiple createHandlerMap call. So there would be a good point to reduce boilerplates.
Although, cancel is not part of observer protocol but this type practically is important and should be handled in many cases (isFetching entity, etc.) in the reducers.

Possible Implementation

createHandlerMap(addFoo, {
  next(state, action) {},
  error(state, action) {},
  complete(state, action) {},
  cancel(state, action) {}
})
@the-dr-lazy
Copy link
Owner Author

Also in many cases error and cancel have shared logic.

@the-dr-lazy the-dr-lazy added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Jan 21, 2019
@the-dr-lazy
Copy link
Owner Author

A solution for shared logic is to handle cancel and error separately:

createHandlerMap(addFoo, {
  next(state, action) {},
  complete(state, action) {},
})
createHandlerMap([addFoo.error, addFoo.cancel], (state, action) => { /* shared logic */ })

@the-dr-lazy the-dr-lazy self-assigned this Mar 26, 2019
@the-dr-lazy the-dr-lazy added this to the v2.2.0 milestone Jun 23, 2019
@the-dr-lazy the-dr-lazy removed this from the v3.1.0 milestone Dec 9, 2019
@kotarella1110
Copy link
Contributor

kotarella1110 commented Dec 10, 2019

Hey @thebrodmann again!
How do you create action creator in this case?

@the-dr-lazy
Copy link
Owner Author

Just by using createActionCreator in an object.

const addFoo = {
  next: createActionCreator('NEXT'),
  error: createActionCreator('ERROR'),
  cancel: createActionCreator('CANCEL'),
  complete: createActionCreator('COMPLETE'),
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants