@@ -7,45 +7,28 @@ import {
7
7
createEffect ,
8
8
ofType ,
9
9
} from '@ngrx/effects' ;
10
- import {
11
- Store ,
12
- select ,
13
- } from '@ngrx/store' ;
14
10
import {
15
11
of ,
16
12
Observable ,
17
13
} from 'rxjs' ;
18
14
import {
19
15
switchMap ,
20
16
catchError ,
21
- withLatestFrom ,
22
17
} from 'rxjs/operators' ;
23
18
24
19
import {
25
20
DaffGenericCategory ,
26
21
DaffGetCategoryResponse ,
27
- DaffCategoryRequestKind ,
28
- DaffCategoryIdRequest ,
29
- DaffCategoryPageMetadata ,
30
22
} from '@daffodil/category' ;
31
23
import {
32
24
DaffCategoryDriver ,
33
25
DaffCategoryServiceInterface ,
34
26
} from '@daffodil/category/driver' ;
35
- import {
36
- DaffError ,
37
- daffFiltersToRequests ,
38
- } from '@daffodil/core' ;
27
+ import { DaffError } from '@daffodil/core' ;
39
28
import { ErrorTransformer } from '@daffodil/core/state' ;
40
29
import { DaffProduct } from '@daffodil/product' ;
41
30
import { DaffProductGridLoadSuccess } from '@daffodil/product/state' ;
42
31
43
- import {
44
- DaffCategoryPageChangeCurrentPage ,
45
- DaffCategoryPageChangePageSize ,
46
- DaffCategoryPageChangeSortingOption ,
47
- DaffCategoryPageProductCollectionActionTypes ,
48
- } from '../actions/category-page-filter.actions' ;
49
32
import {
50
33
DaffCategoryPageLoadSuccess ,
51
34
DaffCategoryPageLoad ,
@@ -54,7 +37,6 @@ import {
54
37
DaffCategoryPageLoadByUrl ,
55
38
} from '../actions/category-page.actions' ;
56
39
import { DAFF_CATEGORY_ERROR_MATCHER } from '../injection-tokens/public_api' ;
57
- import { getDaffCategorySelectors } from '../selectors/category.selector' ;
58
40
59
41
@Injectable ( )
60
42
export class DaffCategoryPageEffects <
@@ -65,20 +47,11 @@ export class DaffCategoryPageEffects<
65
47
private actions$ : Actions ,
66
48
@Inject ( DaffCategoryDriver ) private driver : DaffCategoryServiceInterface < V , W > ,
67
49
@Inject ( DAFF_CATEGORY_ERROR_MATCHER ) private errorMatcher : ErrorTransformer ,
68
- private store : Store < any > ,
69
50
) { }
70
51
71
- private categorySelectors = getDaffCategorySelectors < V , W > ( ) ;
72
-
73
52
loadCategoryPage$ : Observable < any > = createEffect ( ( ) => this . actions$ . pipe (
74
53
ofType ( DaffCategoryPageActionTypes . CategoryPageLoadAction ) ,
75
- switchMap ( ( action : DaffCategoryPageLoad ) => this . processCategoryGetRequest ( action . request ) ) ,
76
- ) ) ;
77
-
78
-
79
- loadCategoryPageByUrl$ : Observable < any > = createEffect ( ( ) => this . actions$ . pipe (
80
- ofType ( DaffCategoryPageActionTypes . CategoryPageLoadByUrlAction ) ,
81
- switchMap ( ( action : DaffCategoryPageLoadByUrl ) => this . driver . getByUrl ( action . request ) . pipe (
54
+ switchMap ( ( action : DaffCategoryPageLoad ) => this . driver . get ( action . request ) . pipe (
82
55
switchMap ( ( resp : DaffGetCategoryResponse < V , W > ) => [
83
56
new DaffProductGridLoadSuccess ( resp . products ) ,
84
57
new DaffCategoryPageLoadSuccess ( resp ) ,
@@ -88,55 +61,14 @@ export class DaffCategoryPageEffects<
88
61
) ) ;
89
62
90
63
91
- changeCategoryPageSize$ : Observable < any > = createEffect ( ( ) => this . actions$ . pipe (
92
- ofType ( DaffCategoryPageProductCollectionActionTypes . CategoryPageChangeSizeAction ) ,
93
- withLatestFrom (
94
- this . store . pipe ( select ( this . categorySelectors . selectCollectionMetadata ) ) ,
95
- ) ,
96
- switchMap ( ( [ action , metadata ] : [ DaffCategoryPageChangePageSize , DaffCategoryPageMetadata ] ) => this . processCategoryGetRequest ( {
97
- ...metadata ,
98
- kind : DaffCategoryRequestKind . ID ,
99
- filterRequests : daffFiltersToRequests ( metadata . filters ) ,
100
- pageSize : action . pageSize ,
101
- } ) ) ,
102
- ) ) ;
103
-
104
-
105
- changeCategoryCurrentPage$ : Observable < any > = createEffect ( ( ) => this . actions$ . pipe (
106
- ofType ( DaffCategoryPageProductCollectionActionTypes . CategoryPageChangeCurrentPageAction ) ,
107
- withLatestFrom (
108
- this . store . pipe ( select ( this . categorySelectors . selectCollectionMetadata ) ) ,
109
- ) ,
110
- switchMap ( ( [ action , metadata ] : [ DaffCategoryPageChangeCurrentPage , DaffCategoryPageMetadata ] ) => this . processCategoryGetRequest ( {
111
- ...metadata ,
112
- kind : DaffCategoryRequestKind . ID ,
113
- filterRequests : daffFiltersToRequests ( metadata . filters ) ,
114
- currentPage : action . currentPage ,
115
- } ) ) ,
116
- ) ) ;
117
-
118
-
119
- changeCategorySort$ : Observable < any > = createEffect ( ( ) => this . actions$ . pipe (
120
- ofType ( DaffCategoryPageProductCollectionActionTypes . CategoryPageChangeSortingOptionAction ) ,
121
- withLatestFrom (
122
- this . store . pipe ( select ( this . categorySelectors . selectCollectionMetadata ) ) ,
123
- ) ,
124
- switchMap ( ( [ action , metadata ] : [ DaffCategoryPageChangeSortingOption , DaffCategoryPageMetadata ] ) => this . processCategoryGetRequest ( {
125
- ...metadata ,
126
- kind : DaffCategoryRequestKind . ID ,
127
- filterRequests : daffFiltersToRequests ( metadata . filters ) ,
128
- appliedSortOption : action . sort . option ,
129
- appliedSortDirection : action . sort . direction ,
130
- } ) ) ,
131
- ) ) ;
132
-
133
- private processCategoryGetRequest ( payload : DaffCategoryIdRequest ) {
134
- return this . driver . get ( payload ) . pipe (
64
+ loadCategoryPageByUrl$ : Observable < any > = createEffect ( ( ) => this . actions$ . pipe (
65
+ ofType ( DaffCategoryPageActionTypes . CategoryPageLoadByUrlAction ) ,
66
+ switchMap ( ( action : DaffCategoryPageLoadByUrl ) => this . driver . getByUrl ( action . request ) . pipe (
135
67
switchMap ( ( resp : DaffGetCategoryResponse < V , W > ) => [
136
68
new DaffProductGridLoadSuccess ( resp . products ) ,
137
69
new DaffCategoryPageLoadSuccess ( resp ) ,
138
70
] ) ,
139
71
catchError ( ( error : DaffError ) => of ( new DaffCategoryPageLoadFailure ( this . errorMatcher ( error ) ) ) ) ,
140
- ) ;
141
- }
72
+ ) ) ,
73
+ ) ) ;
142
74
}
0 commit comments