Closed
Description
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:
const result = entry.length > 1
? Promise.all(entry.map(handler => handler(payload)))
: entry[0](payload);
result.then(() => this._actionSubscribers.forEach(sub => sub(action, this.state)));
return result;
I could open a pull request if that looks reasonable (will add tests, etc.)
Metadata
Metadata
Assignees
Labels
No labels