xref: /expo/home/redux/SessionReducer.ts (revision 5270acf4)
1import { Record } from 'immutable';
2
3export type SessionObject = {
4  sessionSecret: string | null;
5};
6
7export type SessionType = Record<SessionObject> & Readonly<SessionObject>;
8
9const SessionState = Record<SessionObject>({
10  sessionSecret: null,
11});
12
13type SessionActions =
14  | {
15      type: 'setSession';
16      payload: SessionObject;
17    }
18  | { type: 'signOut' };
19
20export default (state: SessionType = new SessionState(), action: SessionActions): SessionType => {
21  switch (action.type) {
22    case 'setSession':
23      return new SessionState(action.payload);
24    case 'signOut':
25      return new SessionState();
26    default:
27      return state;
28  }
29};
30