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

Logging unhandled actions #43

Open
leonp-s opened this issue Sep 9, 2019 · 3 comments
Open

Logging unhandled actions #43

leonp-s opened this issue Sep 9, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@leonp-s
Copy link

leonp-s commented Sep 9, 2019

I was just wondering if there is currently a way to log actions that are called but not handled/don't exist?

@leonp-s leonp-s changed the title Loggin unhandled actions Logging unhandled actions Sep 9, 2019
@albertogasparin
Copy link
Collaborator

You mean like:

const Component = () => {
  const [state, actions] = useCounter();
  useEffect(() => { 
    actions.nonExistentAction();
  })
}

In that case you will get the standard js error undefined is not a function.
Different case if you are talking about async actions that you forget to catch, but cannot think of a solution for that on the library side

@albertogasparin albertogasparin added the question Further information is requested label Sep 10, 2019
@leonp-s
Copy link
Author

leonp-s commented Sep 10, 2019

Hmm, was really talking async actions. Guessing its not too possible then?

@albertogasparin
Copy link
Collaborator

Not at the moment. To support that we should expose an API to add enhancers, like Redux, so you can wrap actions (and, for instance, add a .catch if the mutator returns a promise).

Sweet-state core is already kind of build with that in mind (see how devtools support is implemented) but never really had the need to add a public API and a dynamic set of enhancers.
In theory, we could expose something like the middleware API: we collect functions into a Set, then create an applyEnhancers (sibling of applyMiddlewares) and change the default export of create-state.js to be the version with all the enhancers applied. So when a store is created you have control over the actions.

If you feel up for the challenge, PRs are welcome, otherwise next time I'll have some spare time I'll give it a go.

@albertogasparin albertogasparin added enhancement New feature or request and removed question Further information is requested labels Sep 17, 2019
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