reducer is added

This commit is contained in:
병준 박 2019-09-19 11:22:49 +09:00
parent 07528f5629
commit b934474aa3
3 changed files with 66 additions and 10 deletions

View File

@ -11,7 +11,7 @@ export const effects: Type<any>[] = [VersionInfoStore.Effects];
export function reducers(state: State | undefined, action: Action) { export function reducers(state: State | undefined, action: Action) {
return combineReducers({ return combineReducers({
versionInfo: VersionInfoStore.reducers versionInfo: VersionInfoStore.reducer
})(state, action); })(state, action);
} }

View File

@ -1,6 +1,23 @@
import { Action, combineReducers } from '@ngrx/store'; import { createReducer, on } from '@ngrx/store';
import { State } from './state'; import { initialState } from './state';
import { fetchSuccess } from './actions';
export function reducers(state: State | undefined, action: Action) { export const reducer = createReducer(
return combineReducers({})(state, action); initialState,
} on(fetchSuccess, (state, action) => {
return {
...state,
profileImageRoot: action.profileRoot,
profileImageUploadUrl: action.profileUploadUrl,
fileUploadMaxSize:
!!action.fileAllowSize &&
!isNaN(action.fileAllowSize) &&
0 < action.fileAllowSize
? action.fileAllowSize
: 0,
fileUploadUrl: action.uploadUrl,
fileDownloadUrl: action.downloadUrl,
serverIp: action.serverIp
};
})
);

View File

@ -1,10 +1,49 @@
import { Selector } from '@ngrx/store'; import { Selector, createSelector } from '@ngrx/store';
// tslint:disable-next-line: no-empty-interface // tslint:disable-next-line: no-empty-interface
export interface State {} export interface State {
profileImageRoot: string | null;
profileImageUploadUrl: string | null;
fileUploadMaxSize: number | null;
fileUploadUrl: string | null;
fileDownloadUrl: string | null;
serverIp: string | null;
}
export const initialState: State = {}; export const initialState: State = {
profileImageRoot: null,
profileImageUploadUrl: null,
fileUploadMaxSize: null,
fileUploadUrl: null,
fileDownloadUrl: null,
serverIp: null
};
export function selectors<S>(selector: Selector<any, State>) { export function selectors<S>(selector: Selector<any, State>) {
return {}; return {
profileImageRoot: createSelector(
selector,
(state: State) => state.profileImageRoot
),
profileImageUploadUrl: createSelector(
selector,
(state: State) => state.profileImageUploadUrl
),
fileUploadMaxSize: createSelector(
selector,
(state: State) => state.fileUploadMaxSize
),
fileUploadUrl: createSelector(
selector,
(state: State) => state.fileUploadUrl
),
fileDownloadUrl: createSelector(
selector,
(state: State) => state.fileDownloadUrl
),
serverIp: createSelector(
selector,
(state: State) => state.serverIp
)
};
} }