-
Notifications
You must be signed in to change notification settings - Fork 435
/
app.reducer.ts
42 lines (34 loc) · 1.18 KB
/
app.reducer.ts
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
/*
* The main (and only) @ngrx/store reducer for the application.
*
* This implements the application's core logic by handling actions
* and producing new versions of the immutable AppState record
* based on those actions.
*/
import { ActionReducer, Action } from '@ngrx/store';
import { List, Range } from 'immutable';
import { AppStateRecord, appStateFactory } from 'app';
// Action definitions
export const LOGIN_USER = 'LOlGIN_USER';
export const LOGOUT_USER = 'LOGOUT_USER';
// The reducer function. Receives actions and produces new application states.
export const appReducer: ActionReducer<AppStateRecord> = (state = makeInitialState(), action: Action) => {
switch (action.type) {
case LOGIN_USER:
console.log(action.payload);
// state.set('loggedInUser', action.payload);
// state.set('loggedIn', true);
return state.merge({ loggedInUser: action.payload, loggedIn: true });
case LOGOUT_USER:
return state.merge(makeInitialState());
default:
return state;
}
}
// Initial AppState, used to bootstrap the reducer.
function makeInitialState() {
return appStateFactory({
loggedIn: false,
loggedInUser: {}
});
}