This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface Employee { | |
id: number; | |
name: string; | |
age: string; | |
salary: string; | |
isPermanent: boolean; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Employee } from '../models/employee'; | |
import { EmployeeFilterOptions } from './actions/employee.action'; | |
export interface IAppState { | |
employees: Employee[]; | |
filterOption: EmployeeFilterOptions; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Employee } from '../models/employee'; | |
import { EmployeeFilterOptions } from './actions/employee.action'; | |
export interface IAppState { | |
employees: Employee[]; | |
filterOption: EmployeeFilterOptions; | |
} | |
export const INITIAL_STATE: IAppState = { | |
employees: null, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { INITIAL_STATE } from '../app.state'; | |
export function appReducer(state = INITIAL_STATE, action) { | |
return state; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { AnyAction } from 'redux'; | |
import { Employee } from '../models/employee'; | |
@Injectable() | |
export class AppActions { | |
static ADD_EMPLOYEE = 'ADD_EMPLOYEE'; | |
addEmployee(emp: Employee): AnyAction { | |
return { type: AppActions.ADD_EMPLOYEE, employee: emp }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { AnyAction } from 'redux'; | |
import { Employee } from '../models/employee'; | |
@Injectable() | |
export class AppActions { | |
static ADD_EMPLOYEE = 'ADD_EMPLOYEE'; | |
deleteEmployee(empId: number): AnyAction { | |
return { type: AppActions.DELETE_EMPLOYEE, id: empId }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { AnyAction } from 'redux'; | |
import { Employee } from '../models/employee'; | |
@Injectable() | |
export class AppActions { | |
static SET_EMPLOYEE_FILTER = 'SET_EMPLOYEE_FILTER'; | |
static ADD_EMPLOYEE = 'ADD_EMPLOYEE'; | |
static DELETE_EMPLOYEE = 'DELETE_EMPLOYEE'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { AnyAction } from 'redux'; | |
import { Employee } from '../models/employee'; | |
@Injectable() | |
export class AppActions { | |
static SET_EMPLOYEE_FILTER = 'SET_EMPLOYEE_FILTER'; | |
setEmployeeFilter(filter: string) { | |
return { type: AppActions.SET_EMPLOYEE_FILTER, option: filter }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Employee } from '../models/employee'; | |
import { AppActions, EmployeeFilterOptions } from './app.actions'; | |
export function appReducer(state = INITIAL_STATE, action) { | |
switch (action.type) { | |
case AppActions.SET_EMPLOYEE_FILTER: | |
return Object.assign({}, state, { | |
filterOption: action.option | |
} as IAppState); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Employee } from '../models/employee'; | |
import { AppActions, EmployeeFilterOptions } from './app.actions'; | |
export function appReducer(state = INITIAL_STATE, action) { | |
switch (action.type) { | |
case AppActions.ADD_EMPLOYEE: | |
action.employee.id = state.employees.length + 1; | |
return Object.assign({}, state, { | |
employees: state.employees.concat(Object.assign({}, action.employee)) | |
} as IAppState); |
OlderNewer