import {BaseStateModel} from "@app/base.state"; import {StateEnum} from "@app/shared/enums/state.enum"; import {GetAllLanguages} from "@app/shared/language.action"; import {LanguageState} from "@app/shared/language.state"; import {GetAllLicenses} from "@app/shared/license.action"; import {LicenseState} from "@app/shared/license.state"; import {GetAllResources, GetAllResourcesFail, GetAllResourcesSuccess} from "@app/shared/shared.action"; import {Action, State, StateContext} from "@ngxs/store"; export interface SharedStateModel extends BaseStateModel { } @State<SharedStateModel>({ name: StateEnum.shared, defaults: { isLoading: false, }, children: [ LanguageState, LicenseState, ], }) export class SharedState { constructor() { } @Action(GetAllResources, {cancelUncompleted: true}) getAllResources(ctx: StateContext<SharedStateModel>, action: GetAllResources) { ctx.patchState({ isLoading: true, }); ctx.dispatch([ new GetAllLanguages(), new GetAllLicenses(), new GetAllResourcesSuccess(), // TO FIX Should be raised only when GetAllLanguagesSuccess and GetAllLicensesSuccess is raised) ]); } @Action(GetAllResourcesSuccess) getAllResourcesSuccess(ctx: StateContext<SharedStateModel>, action: GetAllResourcesSuccess) { ctx.patchState({ isLoading: false, }); } @Action(GetAllResourcesFail) getAllResourcesFail(ctx: StateContext<SharedStateModel>) { ctx.patchState({ isLoading: false, }); } }