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