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

Allow duplicate action-creator names, or warn on their creation. #1

Open
Rossh87 opened this issue Aug 23, 2021 · 0 comments
Open

Allow duplicate action-creator names, or warn on their creation. #1

Rossh87 opened this issue Aug 23, 2021 · 0 comments

Comments

@Rossh87
Copy link
Owner

Rossh87 commented Aug 23, 2021

Per the FAQ,

If you have two handler function, handlerOne and handlerTwo, and two components ComponentOne and ComponentTwo, you cannot call useFPReducer in ComponentOne with the handler-mapping object {RUN_HANDLER: handlerOne} and then call useFPReducer in ComponentTwo with the handler-mapping object {RUN_HANDLER: handlerTwo}. If the key RUN_HANDLER is re-used like this and ComponentOne is the first to render in your app, only handlerOne will be associated with the action {type: 'RUN_HANDLER'}. handlerTwo won't be registered with react-use-fp, and dispatching {type: 'RUN_HANDLER'} from ComponentTwo may cause handlerOne to run.

This is not a pit of success. React creates the expectation that the effects of any calls to dispatch will be limited to the state of the component that called useReducer; react-use-fp should honor that expectation. Manually ensuring uniqueness of every key of every handler-mapping object within the application is fragile. react-use-fp should implement some combination of the following behaviors:

  1. Warn in dev mode whenever a user tries to register a handler to an action of a duplicate type
  2. Panic/break in the above situation
  3. Cause a typescript compiler error. Not sure this is possible.
  4. Warn/break if a handler 'takes' an action that was dispatched from an inappropriate place
  5. Maintain an association between a handler's initiating 'type' and the scope in which it was created, which would make it possible for duplicates to co-exist without problems, but would be tricky to implement without creating a memory leak whenever a component unmounted and re-mounted.
Rossh87 added a commit that referenced this issue Aug 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant