diff options
Diffstat (limited to 'vid-webpack-master/src/app/shared/storeUtil/utils/global')
3 files changed, 114 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.actions.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.actions.ts new file mode 100644 index 000000000..609ec69f4 --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.actions.ts @@ -0,0 +1,37 @@ +import {Action, ActionCreator} from "redux"; + +export enum GlobalActions { + UPDATE_NAME = 'UPDATE_NAME', + UPDATE_FLAGS = 'UPDATE_FLAGS', + UPDATE_DRAWING_BOARD_STATUS = 'UPDATE_DRAWING_BOARD_STATUS' +} + +export interface UpdateGlobalAction extends Action { + name?: string; +} + +export interface UpdateFlagsAction extends Action { + flags?: any; +} + +export interface UpdateDrawingBoardStatusAction extends Action{ + drawingBoardStatus?: any; +} + +export const updateName: ActionCreator<UpdateGlobalAction> = + (name) => ({ + type: GlobalActions.UPDATE_NAME, + name: name + }); + +export const updateFlags: ActionCreator<UpdateFlagsAction> = + (flags) => ({ + type: GlobalActions.UPDATE_FLAGS, + flags: flags + }); + +export const updateDrawingBoardStatus: ActionCreator<UpdateDrawingBoardStatusAction> = + (drawingBoardStatus) => ({ + type: GlobalActions.UPDATE_DRAWING_BOARD_STATUS, + drawingBoardStatus: drawingBoardStatus + }); diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.spec.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.spec.ts new file mode 100644 index 000000000..4fc80863a --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.spec.ts @@ -0,0 +1,48 @@ +import {GlobalActions, UpdateFlagsAction, UpdateGlobalAction, UpdateDrawingBoardStatusAction} from "./global.actions"; +import {globalReducer} from "./global.reducers"; + + +describe('globalReducer', () => { + + test('#UPDATE_FLAGS : should update global flags', () => { + const flags = { + 'A' : 'A', + 'B' : 'B', + 'C' : 'C', + 'D' : 'D' + }; + let flagsState = globalReducer(<any>{global : {}}, + <UpdateFlagsAction>{ + type: GlobalActions.UPDATE_FLAGS, + flags : flags + }).flags; + + expect(flagsState).toBeDefined(); + expect(<any>flagsState).toEqual(<any>flags); + }); + + test('#UPDATE_NAME : should update global name', () => { + const name = 'name'; + let globalState = globalReducer(<any>{global : {}}, + <UpdateGlobalAction>{ + type: GlobalActions.UPDATE_NAME, + name : name + }); + expect(globalState).toBeDefined(); + expect(globalState.name).toEqual(name); + }); + + test('#UPDATE_DRAWING_BOARD_STATUS : should update global drawing board status', ()=> { + const drawingBoardStatus = 'EDIT'; + let globalDrawingBoardState = globalReducer(<any>{global : {}}, + <UpdateDrawingBoardStatusAction>{ + type: GlobalActions.UPDATE_DRAWING_BOARD_STATUS, + drawingBoardStatus : drawingBoardStatus + }); + expect(globalDrawingBoardState).toBeDefined(); + expect(globalDrawingBoardState.drawingBoardStatus).toEqual(drawingBoardStatus); + }); +}); + + + diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.ts new file mode 100644 index 000000000..f9e083414 --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.ts @@ -0,0 +1,29 @@ +import {Action} from 'redux'; +import {GlobalActions, UpdateFlagsAction, UpdateGlobalAction, UpdateDrawingBoardStatusAction} from "./global.actions"; + +export interface GlobalState { + name : string; + flags : { [key: string]: boolean }; + drawingBoardStatus : string; +} + +const initialState: GlobalState = { + name : null, + flags : null, + drawingBoardStatus : null +}; + +export const globalReducer = + function (state: GlobalState = initialState, action: Action): GlobalState { + switch (action.type) { + case GlobalActions.UPDATE_NAME: + return Object.assign(state, state, (<UpdateGlobalAction>action)); + case GlobalActions.UPDATE_FLAGS: + Object.assign(state, (<UpdateFlagsAction>action)); + return Object.assign({}, state); + case GlobalActions.UPDATE_DRAWING_BOARD_STATUS: + return Object.assign(state, state, (<UpdateDrawingBoardStatusAction>action)); + default: + return state; + } + }; |