I am developing with aurelia and using aurelia-store for app state management. On loading data from server, I want to change an isLoading field true/false to show mask on related components. So I have defined a property in my state isLoading
(for example). In the loading action I want first change the loading state to true and after data retrieved to false. So that according to the value of this field (isLoading) I want to display the mask over component.
I want something like this:
export async function getRoles(state) {
try {
return Object.assign({}, state, { isRolesListLoading: {busy: true} });
const getRoles = await accountManagement.getRoles();
return Object.assign({}, state, { getRoles, isRolesListLoading: {busy: false} });
} catch (error) {
console.log('error getRoles "error": ', error);
}
}
but as I have figured from aurelia documentations, two state changes are not permitted in one action.
What should I do?
And I have an idea to dispatch another action in this action first to make isLoading true and then do the job. Something like this:
export async function getRoles(state) {
try {
desiredDispatch('goToLoadingState'); // fake code
const getRoles = await accountManagement.getRoles();
return Object.assign({}, state, { getRoles, isRolesListLoading: {busy: false} });
} catch (error) {
console.log('error getRoles "error": ', error);
}
}
But I can't find some documentation on how to dispatch another action in one action.
What are the possible solutions?