Skip to content

Commit

Permalink
feat: ✨ fetch recipes from MealRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
yjaaidi committed Nov 3, 2023
1 parent 518b5df commit e77422d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions apps/whiskmate/src/app/meal-planner/meal-planner.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,23 @@ export class MealPlanner {
constructor() {
this.recipes$ = this._recipes$.asObservable();

this._addRecipe$
.pipe(
const effects = [
/* Fetch meals from repository. */
this._mealRepository
.getMeals()
.pipe(tap((recipes) => this._recipes$.next(recipes))),
/* Add meals to repository. */
this._addRecipe$.pipe(
mergeMap((recipe) =>
this._mealRepository.addMeal(recipe).pipe(map(() => recipe))
),
takeUntilDestroyed()
)
.subscribe((recipe) =>
this._recipes$.next([...this._recipes$.value, recipe])
);
tap((recipe) => this._recipes$.next([...this._recipes$.value, recipe]))
),
];

merge(...effects)
.pipe(takeUntilDestroyed())
.subscribe();
}

addRecipe(recipe: Recipe) {
Expand Down

0 comments on commit e77422d

Please sign in to comment.