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 getOnline = state => state.getIn(["status", 'online']) |
|
8 |
|
9 export const getToken = state => state.getIn(['authStatus','token']) |
|
10 |
|
11 const getSessionMapSelector = actionVal => state => |
|
12 state.get('sessions') |
|
13 .filter(s => s.get('action') === actionVal) |
|
14 .reduce( |
|
15 (res, obj) => { |
|
16 return res.set(obj.get('_id'), obj); |
|
17 }, |
|
18 Immutable.Map() |
|
19 ); |
|
20 |
|
21 const getNoteMapSelector = actionVal => state => { |
|
22 const deletedSessions = state.get('sessions') |
|
23 .filter(s => s.get('action') === ActionEnum.DELETED) |
|
24 .reduce( |
|
25 (res, obj) => { |
|
26 return res.set(obj.get('_id'), obj); |
|
27 }, |
|
28 Immutable.Map() |
|
29 ); |
|
30 return state.get('notes') |
|
31 .filter(n => (n.get('action') === actionVal && !deletedSessions.has(n.get('session')))) |
|
32 .reduce( |
|
33 (res, obj) => { |
|
34 return res.set(obj.get('_id'), obj); |
|
35 }, |
|
36 Immutable.Map() |
|
37 ); |
|
38 } |
|
39 |
|
40 |
|
41 export const getUpdatedSessions = getSessionMapSelector(ActionEnum.UPDATED); |
|
42 |
|
43 export const getCreatedSessions = getSessionMapSelector(ActionEnum.CREATED); |
|
44 |
|
45 export const getDeletedSessions = getSessionMapSelector(ActionEnum.DELETED); |
|
46 |
|
47 export const getUpdatedNotes = getNoteMapSelector(ActionEnum.UPDATED); |
|
48 |
|
49 export const getCreatedNotes = getNoteMapSelector(ActionEnum.CREATED); |
|
50 |
|
51 export const getDeletedNotes = getNoteMapSelector(ActionEnum.DELETED); |
|