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

Feature request: reset reducer for simple stores #2

Open
mturco opened this issue Feb 25, 2019 · 2 comments
Open

Feature request: reset reducer for simple stores #2

mturco opened this issue Feb 25, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@mturco
Copy link

mturco commented Feb 25, 2019

In namely/frontend, it is somewhat common to reset store properties to their default value in setup operations. For example:

dispatch(setError(null));

For collection stores we can just call the provided clear action but it'd be nice if there was also a reset action for simple stores that just sets the value to the defaultValue. For example:

const {
  set: setError,
  reset: resetError,
  reducer: validationErrors,
} = simpleStore('ui/error', { defaultValue: null });
@mturco mturco added the enhancement New feature or request label Feb 25, 2019
@albancreton
Copy link
Contributor

I think, because it is specific, that it is better to keep it outside of the library
you can in your store.js have

const defaultValue = null;
const {
  set: setError,
  reducer: validationErrors,
} = simpleStore('ui/error', { defaultValue });

export const resetError = () => setError(defaultValue);

@mturco
Copy link
Author

mturco commented Feb 25, 2019

Sure, that would work. Is it specific to my use case though? I feel like it's just the simple store equivalent of collection store's clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants