-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Action subscribers do not wait for associated actions to resolve #1098
Comments
@LinusBorg interesting, thanks for providing that context. I'm trying to implement undo/redo, which a bit different than logging in that mutations represent a state change, but actions represent the actual "history steps" in state that the user cares about undoing. Without a way to notify some centralized subscriber when an action resolves, there is no built-in way of tracking those "logical" history changes. I can probably wrap all (or a subset) of my actions with a function that does the waiting/reporting for me. I saw the term "action enhancer" thrown around a couple of times, but the vuexfire docs weren't very clear. The problem with this solution is, after refactoring my existing store, if anyone in the future forgets or doesn't know to wrap their actions with this action wrapper, then they are suddenly excluded from the history tracking. I understand that |
I think extending For example: store.subscribeAction({
before () { /* called before dispatching action */ },
after () { /* called after the returned Promise is resolved */ }
}) |
@ktsn that would be awesome. I'll take a crack at it. |
Action subscribers are called before the action by default. This allows them to specify before and after subscribers where the after subscriber is called when the action resolves
make sure that the before subscriber is called before the action, while the after subscriber is called after it resolves
Generalize subscribeAction's type declaration to accept both a function or an object and add type tests for that
Looking forward for this! Any idea when will this be released? |
@johnmerced the pr is here, waiting on Evan's review. |
@wa3l Awesome! We are looking forward for this! 👍 Thank you! |
Any updates or deadline on this feature? |
* allow action subscribers to specify before/after hooks (#1098) Action subscribers are called before the action by default. This allows them to specify before and after subscribers where the after subscriber is called when the action resolves * add test cases for the new before/after action subscribers (#1098) make sure that the before subscriber is called before the action, while the after subscriber is called after it resolves * Replace Promise initialization with shorter form (#1098) * Update subscribeAction type declaration and add type tests (#1098) Generalize subscribeAction's type declaration to accept both a function or an object and add type tests for that
What problem does this feature solve?
I noticed that my store action subscribers were being called before the actions finish. Digging into the code, it looks like not only do action subscribers not wait on the actions to resolve, but they execute before the action. Mutation subscribers, on the other hand, seem to work as expected (call mutation first, call subscriber second). Since actions are often asynchronous (and vuex always wraps them with promises), I think it makes more sense to wait on the action and then call subscribers.
I wasn't sure if this was intentional or not, hence the feature request.
What does the proposed API look like?
I think something like the following would be more in line with what developers expect:
I could open a pull request if that looks reasonable (will add tests, etc.)
The text was updated successfully, but these errors were encountered: