forked from jeffbski/redux-logic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reducer.js
43 lines (40 loc) · 982 Bytes
/
reducer.js
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
import { key, NOTIFY_CREATE, NOTIFY_QUEUE, NOTIFY_REMOVE, NOTIFY_DISPLAY_QUEUED } from './actions';
export const selectors = {
messages: state => state[key].messages,
queue: state => state[key].queue
};
const initialState = {
messages: [],
queue: []
};
export default function reducer(state = initialState, action) {
switch(action.type) {
case NOTIFY_CREATE :
return {
...state,
messages: [...state.messages, action.payload]
};
case NOTIFY_QUEUE :
return {
...state,
queue: [...state.queue, action.payload]
};
case NOTIFY_REMOVE :
return {
...state,
messages: state.messages
.filter(m => action.payload.indexOf(m) === -1)
};
case NOTIFY_DISPLAY_QUEUED :
{
const msgs = action.payload;
return {
...state,
messages: [...state.messages, ...msgs],
queue: state.queue.filter(m => msgs.indexOf(m) === -1)
};
}
default:
return state;
}
}