66 lines
2.3 KiB
TypeScript
66 lines
2.3 KiB
TypeScript
|
import { tassign } from 'tassign';
|
||
|
import { IItemTypes} from '../models/item.types';
|
||
|
import { IListItem } from '../models/list.item';
|
||
|
import { IUser } from '../models/user';
|
||
|
import * as appCommonActions from '../actions/app-common.actions';
|
||
|
import { createSelector, createFeatureSelector, ActionReducerMap } from '@ngrx/store';
|
||
|
|
||
|
import { MODULE_NAME } from '../module-name';
|
||
|
|
||
|
export interface State {
|
||
|
openedModalName: string,
|
||
|
initialized: boolean,
|
||
|
rootItems: IListItem[],
|
||
|
itemTypes: IItemTypes,
|
||
|
user:IUser
|
||
|
}
|
||
|
|
||
|
export const initialState: State = {
|
||
|
openedModalName: null,
|
||
|
initialized: false,
|
||
|
rootItems: [],
|
||
|
itemTypes: {},
|
||
|
user:null
|
||
|
}
|
||
|
|
||
|
export function reducer(state = initialState, action: appCommonActions.Actions ): State {
|
||
|
switch (action.type) {
|
||
|
case appCommonActions.INITUSERSUCCESS: {
|
||
|
let a = action as appCommonActions.InitUserSuccess;
|
||
|
return tassign(state, { user: a.user });
|
||
|
}
|
||
|
case appCommonActions.INITROOTSUCCESS: {
|
||
|
let a = action as appCommonActions.InitRootSuccess;
|
||
|
return tassign(state, { rootItems:a.items});
|
||
|
}
|
||
|
case appCommonActions.OPENMODAL: {
|
||
|
return tassign(state, { openedModalName: action.modalName });
|
||
|
}
|
||
|
case appCommonActions.CLOSEMODAL: {
|
||
|
return tassign(state, { openedModalName: null });
|
||
|
}
|
||
|
case appCommonActions.INITIALIZED: {
|
||
|
return tassign(state, { initialized: true });
|
||
|
}
|
||
|
case appCommonActions.LOADITEMTYPESSUCCESS: {
|
||
|
let a = action as appCommonActions.LoadItemTypesSuccess;
|
||
|
return tassign(state, { itemTypes: a.itemTypes });
|
||
|
}
|
||
|
default: {
|
||
|
return state;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const getOpenedModalName = (state: State) => state.openedModalName;
|
||
|
export const getInitialized = (state: State) => state.initialized;
|
||
|
export const getItemTypes = (state: State) => state.itemTypes;
|
||
|
export const getRootItems = (state: State) => state.rootItems;
|
||
|
|
||
|
export const selectAppCommonState = createFeatureSelector<State>(MODULE_NAME);
|
||
|
|
||
|
export const selectOpenedModalName = createSelector(selectAppCommonState, getOpenedModalName);
|
||
|
export const selectGetInitialized = createSelector(selectAppCommonState, getInitialized);
|
||
|
export const selectGetItemTypes = createSelector(selectAppCommonState, getItemTypes);
|
||
|
export const selectGetRootItems = createSelector(selectAppCommonState, getRootItems);
|