equal
deleted
inserted
replaced
|
1 import Immutable from 'immutable'; |
|
2 import { ActionEnum } from '../constants' |
|
3 |
|
4 |
|
5 const getSessionMapSelector = actionVal => state => |
|
6 state.get('sessions') |
|
7 .filter(s => s.get('action') === actionVal) |
|
8 .reduce( |
|
9 (res, obj) => { |
|
10 return res.set(obj.get('_id'), obj); |
|
11 }, |
|
12 Immutable.Map() |
|
13 ); |
|
14 |
|
15 const getNoteMapSelector = actionVal => state => { |
|
16 const deletedSessions = state.get('sessions') |
|
17 .filter(s => s.get('action') === ActionEnum.DELETED) |
|
18 .reduce( |
|
19 (res, obj) => { |
|
20 return res.set(obj.get('_id'), obj); |
|
21 }, |
|
22 Immutable.Map() |
|
23 ); |
|
24 return state.get('notes') |
|
25 .filter(n => (n.get('action') === actionVal && !deletedSessions.has(n.get('session')))) |
|
26 .reduce( |
|
27 (res, obj) => { |
|
28 return res.set(obj.get('_id'), obj); |
|
29 }, |
|
30 Immutable.Map() |
|
31 ); |
|
32 } |
|
33 |
|
34 |
|
35 export const getUpdatedSessions = getSessionMapSelector(ActionEnum.UPDATED); |
|
36 |
|
37 export const getCreatedSessions = getSessionMapSelector(ActionEnum.CREATED); |
|
38 |
|
39 export const getDeletedSessions = getSessionMapSelector(ActionEnum.DELETED); |
|
40 |
|
41 export const getUpdatedNotes = getNoteMapSelector(ActionEnum.UPDATED); |
|
42 |
|
43 export const getCreatedNotes = getNoteMapSelector(ActionEnum.CREATED); |
|
44 |
|
45 export const getDeletedNotes = getNoteMapSelector(ActionEnum.DELETED); |