forked from ng-book/angular2-redux-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.reducer.ts
43 lines (37 loc) · 1.06 KB
/
users.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
42
43
/**
* Copyright 2016, Fullstack.io, LLC.
*
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import { Action } from 'redux';
import { User } from './user.model';
import * as UserActions from './user.actions';
import { createSelector } from 'reselect';
/**
* This file describes the state concerning Users, how to modify it through
* the reducer, and the selectors.
*/
export interface UsersState {
currentUser: User;
};
const initialState: UsersState = {
currentUser: null
};
export const UsersReducer =
function(state: UsersState = initialState, action: Action): UsersState {
switch (action.type) {
case UserActions.SET_CURRENT_USER:
const user: User = (<UserActions.SetCurrentUserAction>action).user;
return {
currentUser: user
};
default:
return state;
}
};
export const getUsersState = (state): UsersState => state.users;
export const getCurrentUser = createSelector(
getUsersState,
( state: UsersState ) => state.currentUser );