-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathperson.js
More file actions
55 lines (45 loc) · 1.06 KB
/
Copy pathperson.js
File metadata and controls
55 lines (45 loc) · 1.06 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
import {List, Record} from 'immutable'
import {appName} from '../config'
import {createSelector} from 'reselect'
/**
* Constants
* */
export const moduleName = 'person'
const prefix = `${appName}/${moduleName}`
export const ADD_PERSON = `${prefix}/ADD_PERSON`
/**
* Reducer
* */
export const ReducerRecord = Record({
peopleList: List()
})
export default function reducer(state = new ReducerRecord(), action) {
const {type, payload} = action
switch (type) {
case ADD_PERSON:
return state.set('peopleList', state.peopleList.push(payload.person))
default:
return state
}
}
/**
* Selectors
* */
export const rootSelector = ({person}) => person
export const personSelector = createSelector(
rootSelector,
(person) => {
return person.peopleList.toArray()
}
)
/**
* Action Creators
* */
export function addPerson(firstName, secondName, email) {
return (dispatch) => {
dispatch({
type: ADD_PERSON,
payload: {person: {firstName, secondName, email}}
})
}
}