-
Notifications
You must be signed in to change notification settings - Fork 30
/
shop-settings-config.state.ts
40 lines (31 loc) · 1.13 KB
/
shop-settings-config.state.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { State, StateContext, NgxsOnInit, Selector } from '@ngxs/store';
import { ShopStateService } from '../shop-state.service';
import { take } from 'rxjs/operators';
import { AppState } from '../../app-state/app.state';
import { AppStateModel } from '../../app-state/app-state.interface';
import { initSettingConfigGroup } from '../../shared/helpers';
interface ShopSettingsConfigModel {
[site: string]: any;
}
const defaultState: ShopSettingsConfigModel = {};
@State<ShopSettingsConfigModel>({
name: 'shopSettingsConfig',
defaults: defaultState
})
export class ShopSettingsConfigState implements NgxsOnInit {
constructor(
private stateService: ShopStateService) {
}
ngxsOnInit({ setState }: StateContext<ShopSettingsConfigModel>) {
return this.stateService.getInitialState('', 'settingsConfig').pipe(
take(1)
).subscribe((settingsConfig) => {
const settingGroups = {};
for (const groupSlug in settingsConfig) {
settingGroups[groupSlug] = initSettingConfigGroup(settingsConfig[groupSlug]);
delete settingGroups[groupSlug][groupSlug];
}
setState(settingGroups);
});
}
}