Skip to content

Instantly share code, notes, and snippets.

View nomanHasan's full-sized avatar

Noman Hasan nomanHasan

View GitHub Profile
@nomanHasan
nomanHasan / todo.reducer.ts
Created October 11, 2017 10:01
5 #todoapp-angular-ngrx
// ........................
export function TodoReducer(state = defaultState, action: Action) {
switch (action.type) {
//...............
case TodoActions.GET_TODOS_SUCCESS: {
@nomanHasan
nomanHasan / todo.reducer.ts
Last active October 12, 2017 11:40
4 #todoapp-angular-ngrx
// ........................
export function TodoReducer(state = defaultState, action: Action) {
switch (action.type) {
//...............
@nomanHasan
nomanHasan / todo.reducer.ts
Last active October 11, 2017 10:00
3 #todoapp-angular-ngrx
// ........................
export function TodoReducer(state = defaultState, action: Action) {
switch (action.type) {
//...............
case TodoActions.CREATE_TODO_SUCCESS: {
@nomanHasan
nomanHasan / todo.reducer.ts
Created October 11, 2017 09:59
2 #todoapp-angular-ngrx
// ........................
export function TodoReducer(state = defaultState, action: Action) {
switch (action.type) {
case TodoActions.CREATE_TODO: {
return {
@nomanHasan
nomanHasan / todo.reducer.ts
Created October 11, 2017 09:57
1 #todoapp-angular-ngrx
import Todo from '../../models/todo.model';
import { initializeTodoState, TodoListState, TodoState } from './todo.state';
import * as TodoActions from './todo.action';
export type Action = TodoActions.All;
const defaultTodoStates: TodoState[] = [
{
...Todo.generateMockTodo(),
...initializeTodoState()
@nomanHasan
nomanHasan / todo.effect.ts
Created October 11, 2017 09:55
5 #todoapp-angular-ngrx
//............................
@Effect()
updateTodo$: Observable<Action> = this.actions$.
ofType<TodoActions.UpdateTodo>(TodoActions.UPDATE_TODO)
.mergeMap(action =>
this.http.put(environment.client.base_url + '/api/todos/', action.payload)
.map((data: Response) => {
return new TodoActions.UpdateTodoSuccess({
@nomanHasan
nomanHasan / todo.effect.ts
Created October 11, 2017 09:55
4 #todoapp-angular-ngrx
//............................
@Effect()
deleteTodo$: Observable<Action> = this.actions$.
ofType<TodoActions.DeleteTodo>(TodoActions.DELETE_TODO)
.mergeMap(action =>
this.http.delete(environment.client.base_url + '/api/todos/' + action.payload._id)
.map((data: Response) => {
return new TodoActions.DeleteTodoSuccess({
@nomanHasan
nomanHasan / todo.effect.ts
Created October 11, 2017 09:54
3 #todoapp-angular-ngrx
//............................
@Effect()
createTodo$: Observable<Action> = this.actions$.
ofType<TodoActions.CreateTodo>(TodoActions.CREATE_TODO)
.mergeMap(action =>
this.http.post(environment.client.base_url + '/api/todos', action.payload)
.map((data: Response) => {
@nomanHasan
nomanHasan / todo.effect.ts
Created October 11, 2017 09:54
2 #todoapp-angular-ngrx
//..............................
@Effect()
GetTodos$: Observable<Action> = this.actions$.
ofType<TodoActions.GetTodos>(TodoActions.GET_TODOS)
.mergeMap(action =>
this.http.get(environment.client.base_url + '/api/todos')
.map((data: Response) => {
console.log(data);
@nomanHasan
nomanHasan / todo.effect.ts
Created October 11, 2017 09:54
1 #todoapp-angular-ngrx
import { TodoState } from './todo.state';
import { environment } from '../../../environments/environment';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/operator/catch';
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { Action } from '@ngrx/store';
import { Actions, Effect } from '@ngrx/effects';