浏览代码

24-343 Cleaning up

ngrx
Nils Dittberner 8 年前
父节点
当前提交
e3a46d8895
共有 7 个文件被更改,包括 3 次插入61 次删除
  1. +0
    -4
      src/app/core/core.module.ts
  2. +1
    -2
      src/app/core/header/header.component.ts
  3. +2
    -2
      src/app/recipes/recipe-detail/recipe-detail.component.ts
  4. +0
    -3
      src/app/recipes/recipe-list/recipe-list.component.ts
  5. +0
    -19
      src/app/recipes/recipe.service.ts
  6. +0
    -2
      src/app/recipes/recipes.component.ts
  7. +0
    -29
      src/app/shared/data-storage.service.ts

+ 0
- 4
src/app/core/core.module.ts 查看文件

@@ -5,8 +5,6 @@ import { HeaderComponent } from "./header/header.component";
import { HomeComponent } from "./home/home.component";
import { SharedModule } from "../shared/shared.module";
import { AppRoutingModule } from "../app-routing.module";
import { RecipeService } from "../recipes/recipe.service";
import { DataStorageService } from "../shared/data-storage.service";
import { AuthInterceptor } from "../shared/auth.interceptor";
import { LoggingInterceptor } from "../shared/logging.interceptor";

@@ -24,8 +22,6 @@ import { LoggingInterceptor } from "../shared/logging.interceptor";
HeaderComponent
],
providers: [
RecipeService,
DataStorageService,
{provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: LoggingInterceptor, multi: true}
],


+ 1
- 2
src/app/core/header/header.component.ts 查看文件

@@ -2,7 +2,6 @@ import { Component, OnInit } from "@angular/core";
import { Store } from "@ngrx/store";
import { Observable } from "rxjs/Observable";

import { DataStorageService } from "../../shared/data-storage.service";
import * as fromApp from '../../ngrx/app.reducers';
import * as fromAuth from '../../auth/ngrx/auth.reducers';
import * as AuthActions from '../../auth/ngrx/auth.actions';
@@ -15,7 +14,7 @@ import * as RecipeActions from '../../recipes/ngrx/recipe.actions';
export class HeaderComponent implements OnInit {
authState: Observable<fromAuth.State>;

constructor(private dataStorageService: DataStorageService, private store: Store<fromApp.AppState>) {}
constructor(private store: Store<fromApp.AppState>) {}

ngOnInit() {
this.authState = this.store.select('auth')


+ 2
- 2
src/app/recipes/recipe-detail/recipe-detail.component.ts 查看文件

@@ -7,7 +7,7 @@ import { Recipe } from '../recipe.model';
import * as ShoppingListActions from '../../shopping-list/ngrx/shopping-list.actions';
import * as fromApp from '../../ngrx/app.reducers';
import * as fromRecipe from '../ngrx/recipe.reducers';
import * as RecipeACtions from '../ngrx/recipe.actions';
import * as RecipeActions from '../ngrx/recipe.actions';

@Component({
selector: 'app-recipe-detail',
@@ -45,7 +45,7 @@ export class RecipeDetailComponent implements OnInit {
}

onDelete() {
this.store.dispatch(new RecipeACtions.DeleteRecipe(this.id));
this.store.dispatch(new RecipeActions.DeleteRecipe(this.id));
this.router.navigate(['/recipes']);
}
}

+ 0
- 3
src/app/recipes/recipe-list/recipe-list.component.ts 查看文件

@@ -3,9 +3,6 @@ import { Router, ActivatedRoute } from '@angular/router';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';


import { Recipe } from '../recipe.model';
import { RecipeService } from '../recipe.service';
import * as fromRecipe from '../ngrx/recipe.reducers';

@Component({


+ 0
- 19
src/app/recipes/recipe.service.ts 查看文件

@@ -1,19 +0,0 @@
import { EventEmitter } from "@angular/core";
import { Subject } from "rxjs/Subject";

import { Recipe } from "./recipe.model";
import { Ingredient } from "../shared/ingredient.model";

export class RecipeService {
recipesChanged = new Subject<Recipe[]>();
private recipes: Recipe[] = [];

replaceRecipes(recipes: Recipe[]) {
this.recipes = recipes;
this.recipesChanged.next(this.recipes.slice());
}

getRecipes() {
return this.recipes.slice();
}
}

+ 0
- 2
src/app/recipes/recipes.component.ts 查看文件

@@ -1,7 +1,5 @@
import { Component, OnInit } from '@angular/core';

import { RecipeService } from './recipe.service';

@Component({
selector: 'app-recipes',
templateUrl: './recipes.component.html',


+ 0
- 29
src/app/shared/data-storage.service.ts 查看文件

@@ -1,29 +0,0 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http';

import { RecipeService } from '../recipes/recipe.service';
import { Recipe } from '../recipes/recipe.model';

@Injectable()
export class DataStorageService {
readonly baseUrl: string = 'https://my-recipe-book-cb837.firebaseio.com/';

constructor(private httpClient: HttpClient,
private recipeService: RecipeService) {}

storeRecipes() {
// const token = this.authService.getToken();
// return this.httpClient.put(this.baseUrl + 'recipes.json?auth=' + token, this.recipeService.getRecipes());
// const req = new HttpRequest('PUT', this.baseUrl, this.recipeService.getRecipes(), {reportProgress: true, params: new HttpParams().set('auth', token)});
// return this.httpClient.request(req);
return this.httpClient.put(this.baseUrl + 'recipes.json', this.recipeService.getRecipes());
}

fetchRecipes() {
this.httpClient.get<Recipe[]>(this.baseUrl + 'recipes.json').subscribe(
recipes => {
this.recipeService.replaceRecipes(recipes);
}
)
}
}

正在加载...
取消
保存