-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Article fovorite/unfavorite duplicated effects
- Loading branch information
1 parent
953ffb5
commit 4ca2726
Showing
7 changed files
with
48 additions
and
74 deletions.
There are no files selected for viewing
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
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
31 changes: 0 additions & 31 deletions
31
libs/articles/data-access/src/lib/+state/article/article.effects.ts
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
35 changes: 35 additions & 0 deletions
35
libs/articles/data-access/src/lib/+state/articles.effects.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { inject } from '@angular/core'; | ||
import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { catchError, concatMap, map, of } from 'rxjs'; | ||
import { articlesActions } from './articles.actions'; | ||
import { ActionsService } from '../services/actions.service'; | ||
|
||
export const favorite$ = createEffect( | ||
(actions$ = inject(Actions), actionsService = inject(ActionsService)) => { | ||
return actions$.pipe( | ||
ofType(articlesActions.favorite), | ||
concatMap(({ slug }) => | ||
actionsService.favorite(slug).pipe( | ||
map((response) => articlesActions.favoriteSuccess({ article: response.article })), | ||
catchError((error) => of(articlesActions.favoriteFailure(error))), | ||
), | ||
), | ||
); | ||
}, | ||
{ functional: true }, | ||
); | ||
|
||
export const unFavorite$ = createEffect( | ||
(actions$ = inject(Actions), actionsService = inject(ActionsService)) => { | ||
return actions$.pipe( | ||
ofType(articlesActions.unfavorite), | ||
concatMap(({ slug }) => | ||
actionsService.unfavorite(slug).pipe( | ||
map((response) => articlesActions.unfavoriteSuccess({ article: response.article })), | ||
catchError((error) => of(articlesActions.unfavoriteFailure(error))), | ||
), | ||
), | ||
); | ||
}, | ||
{ functional: true }, | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import { Routes } from '@angular/router'; | ||
import { provideEffects } from '@ngrx/effects'; | ||
import { provideState } from '@ngrx/store'; | ||
import { articleEffects, articleFeature } from '@realworld/articles/data-access'; | ||
import { articleEffects, articleFeature, articlesEffects } from '@realworld/articles/data-access'; | ||
import { ArticleGuardService } from './article-guard.service'; | ||
import { ArticleComponent } from './article.component'; | ||
|
||
export const ARTICLE_ROUTES: Routes = [ | ||
{ | ||
path: ':slug', | ||
component: ArticleComponent, | ||
providers: [provideState(articleFeature), provideEffects(articleEffects)], | ||
providers: [provideState(articleFeature), provideEffects(articleEffects, articlesEffects)], | ||
canActivate: [ArticleGuardService], | ||
}, | ||
]; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { Routes } from '@angular/router'; | ||
import { provideEffects } from '@ngrx/effects'; | ||
import { provideState } from '@ngrx/store'; | ||
import { articleListEffects, articleListFeature } from '@realworld/articles/data-access'; | ||
import { articleListEffects, articleListFeature, articlesEffects } from '@realworld/articles/data-access'; | ||
import { HomeComponent } from './home.component'; | ||
|
||
export const HOME_ROUTES: Routes = [ | ||
{ | ||
path: '', | ||
component: HomeComponent, | ||
providers: [provideState(articleListFeature), provideEffects(articleListEffects)], | ||
providers: [provideState(articleListFeature), provideEffects(articleListEffects, articlesEffects)], | ||
}, | ||
]; |
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