forked from danielstern/express-react-fullstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreducer.js
More file actions
77 lines (75 loc) · 2.61 KB
/
reducer.js
File metadata and controls
77 lines (75 loc) · 2.61 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { combineReducers } from 'redux';
import * as mutations from './mutations'
let defaultState = {
session:{},
comments:[],
users:[],
groups:[],
tasks:[]
};
export const reducer = combineReducers({
session(userSession = defaultState.session,action){
let {type,authenticated, session} = action;
switch(type){
case mutations.SET_STATE:
return {...userSession, id: action.state.session.id};
case mutations.REQUEST_AUTHENTICATE_USER:
return {...userSession, authenticated:mutations.AUTHENTICATING};
case mutations.PROCESSING_AUTHENTICATE_USER:
return {...userSession, authenticated};
default:
return userSession;
}
},
comments:(comments = defaultState.comments,action)=>{
switch (action.type) {
case mutations.ADD_TASK_COMMENT:
let {type,owner,task,content,id} = action;
return [...comments,{owner,task,content,id}];
case mutations.SET_STATE:
return action.state.comments;
}
return comments;
},
users:(users = defaultState.users,action)=>{
switch (action.type) {
case mutations.SET_STATE:
return action.state.users;
}
return users;
},
groups:(groups = defaultState.groups,action)=>{
switch (action.type) {
case mutations.SET_STATE:
return action.state.groups;
}
return groups;
},
tasks(tasks = defaultState.tasks,action){
switch(action.type) {
case mutations.SET_STATE:
return action.state.tasks;
case mutations.SET_TASK_COMPLETE:
return tasks.map(task=>{
return (task.id === action.taskID) ? {...task,isComplete:action.isComplete} : task;
});
case mutations.SET_TASK_GROUP:
return tasks.map(task=>{
return (task.id === action.taskID) ? {...task, group:action.groupID} : task;
});
case mutations.SET_TASK_NAME:
return tasks.map(task=> {
return (task.id === action.taskID) ? {...task, name: action.name} : task;
});
case mutations.CREATE_TASK:
return [...tasks,{
id:action.taskID,
name:"New Task",
group:action.groupID,
owner:action.ownerID,
isComplete:false
}]
}
return tasks;
}
});