Description
What problem does this feature solve?
If you subscribe to an action an return a promise or use an await statement, the code does not wait for the request to be complete. This is a problem when you implement a component as a plugin. Communication between components can be handled by the subscribeAction. But retrieving data and pushing it into the state using the afore mentioned methods will not result in any data since the service does not wait for it to be completed.
This feature would be very usefull for components as plugins that can be fully compartmentalized and plugged into different applications. Configuration retrieval can then be defined in the subscribeAction allowing different implementations over multiple applications.
What does the proposed API look like?
Example for before action:
Current code in src/store.js line 132:
try {
this._actionSubscribers
.filter(sub => sub.before)
.forEach(sub => sub.before(action, this.state))
}
Should be:
try {
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index ) {
await callback(array[index], index, array);
}
}
await asyncForEach(this._actionSubscribers
.filter(function (sub) { return sub.before; }), async function (sub) {
return await sub.before(action, this$1.state);
});
}
dispatch function should be async as wel.