1
- import { ChangeDetectorRef , Directive , OnDestroy } from '@angular/core' ;
1
+ import { Directive , OnDestroy } from '@angular/core' ;
2
2
import { Sort } from '@angular/material/sort' ;
3
3
import { select , Store } from '@ngrx/store' ;
4
4
import {
7
7
ProductsPartialState ,
8
8
} from '@pedro/core' ;
9
9
import { Category , Pagination } from '@pedro/data' ;
10
- import { observableReducer , stateChanges } from '@pedro/utilities' ;
11
- import { merge , Subject , Subscription } from 'rxjs' ;
10
+ import { observableReducer } from '@pedro/utilities' ;
11
+ import { merge , Observable , Subject , Subscription } from 'rxjs' ;
12
12
import {
13
13
debounceTime ,
14
14
distinctUntilChanged ,
@@ -30,7 +30,7 @@ import {
30
30
31
31
@Directive ( )
32
32
export class Products implements OnDestroy {
33
- state : ProductsComponentState ;
33
+ readonly state$ : Observable < ProductsComponentState > ;
34
34
35
35
readonly setState = new Subject < Partial < ProductsComponentState > > ( ) ;
36
36
@@ -50,10 +50,7 @@ export class Products implements OnDestroy {
50
50
51
51
protected readonly subscriptions = new Subscription ( ) ;
52
52
53
- constructor (
54
- private readonly store : Store < ProductsPartialState > ,
55
- private readonly changeDetectorRef : ChangeDetectorRef
56
- ) {
53
+ constructor ( private readonly store : Store < ProductsPartialState > ) {
57
54
const categorySlice$ = this . category$ . pipe (
58
55
map ( ( category ) => ( { category } ) )
59
56
) ;
@@ -98,21 +95,14 @@ export class Products implements OnDestroy {
98
95
99
96
const storeSlice$ = this . store . pipe ( select ( selectProductComponentState ) ) ;
100
97
101
- const state$ = stateChanges (
98
+ this . state$ = observableReducer (
102
99
PRODUCTS_COMPONENT_INITIAL_STATE ,
103
100
storeSlice$ ,
104
101
resetPage$ ,
105
102
changePage$ ,
106
103
this . setState
107
- ) . pipe (
108
- tap ( ( state ) => {
109
- this . state = state ;
110
- this . changeDetectorRef . detectChanges ( ) ;
111
- } )
112
104
) ;
113
105
114
- this . subscriptions . add ( state$ . subscribe ( ) ) ;
115
-
116
106
this . subscriptions . add ( effects$ . subscribe ( ) ) ;
117
107
}
118
108
0 commit comments