-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreducer.tsx
40 lines (36 loc) · 1.16 KB
/
reducer.tsx
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
const Reducer = (state: State, action: Action): State => {
switch (action.type) {
case 'NEW_WINDOW': {
const props = action.payload;
var windows = state.windowsOpen.find( x => x.id === props.id) === undefined ?
[...state.windowsOpen, { id: props.id, header : props.header, title : props.title } ] as Array<AppWindow> : state.windowsOpen;
return {
...state,
focusedWindow: props.id,
windowsOpen: windows
}
}
case 'FOCUSED_WINDOW':{
return {
...state,
focusedWindow : action.payload
}
}
case 'CLOSE_WINDOW':{
return {
...state,
focusedWindow : null ,
windowsOpen: state.windowsOpen.filter(x => x.id !== action.payload)
}
}
case 'CHANGE_BACKGROUND' : {
return {
...state,
backgroundImage : action.payload
}
}
default:
return state;
}
};
export default Reducer;