-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathuserStore.ts
31 lines (28 loc) · 936 Bytes
/
userStore.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
import { createStore } from "redux";
import { Injectable } from "angular2/core";
import { Record } from "immutable";
import { ReduxStore } from "angular2-redux-store";
import { Actions } from "./userActions";
export const userStoreReducer = (state:any = {}, action:any) => {
switch (action.type) {
case Actions.ADD_USER:
var newState = {
users: state.users.concat({name: action.newUser.name})
};
return newState;
case Actions.REMOVE_USER:
var newState = {
users: state.users.slice(0, action.userToRemoveIndex).concat(state.users.slice(action.userToRemoveIndex + 2))
};
return newState;
default:
return state;
}
}
var userStore = createStore(userStoreReducer, {users: []});
@Injectable()
export class UserStore extends ReduxStore {
constructor(){
super(userStore);
}
}