File tree 4 files changed +24
-11
lines changed
4 files changed +24
-11
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "typescript.tsdk" : " node_modules/typescript/lib"
3
+ }
Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ import { CartModule } from './cart/cart.module';
8
8
import { MatToolbarModule , MatIconModule } from '@angular/material' ;
9
9
import { ProductDetailsModule } from './product-details/product-details.module' ;
10
10
import { CartDetailsModule } from './cart-details/cart-details.module' ;
11
+ import { StoreModule } from '@ngrx/store' ;
12
+ import { StoreDevtoolsModule } from '@ngrx/store-devtools' ;
13
+ import { reducer } from './reducer' ;
11
14
12
15
@NgModule ( {
13
16
declarations : [ AppComponent ] ,
@@ -20,6 +23,8 @@ import { CartDetailsModule } from './cart-details/cart-details.module';
20
23
ProductDetailsModule ,
21
24
MatIconModule ,
22
25
MatToolbarModule ,
26
+ StoreModule . forRoot ( { products : reducer } ) ,
27
+ StoreDevtoolsModule . instrument ( { maxAge : 50 } ) ,
23
28
] ,
24
29
bootstrap : [ AppComponent ] ,
25
30
} )
Original file line number Diff line number Diff line change 1
- import { Component , OnInit } from '@angular/core' ;
2
- import { Observable } from 'rxjs' ;
1
+ import { Component } from '@angular/core' ;
3
2
4
3
import { Product } from '../model/product' ;
5
- import { data } from '../services/product-data' ;
6
- import { ProductService } from '../services/product.service' ;
4
+ import { Store } from '@ngrx/store' ;
7
5
8
6
@Component ( {
9
7
selector : 'app-home' ,
10
8
templateUrl : './home.component.html' ,
11
9
styleUrls : [ './home.component.scss' ] ,
12
10
} )
13
- export class HomeComponent implements OnInit {
14
- products$ : Observable < Product [ ] > ;
11
+ export class HomeComponent {
12
+ products$ = this . store . select ( state => state . products ) ;
15
13
16
- constructor ( private readonly productService : ProductService ) { }
17
-
18
- ngOnInit ( ) {
19
- this . products$ = this . productService . getProducts ( ) ;
20
- }
14
+ constructor ( private readonly store : Store < { products : Product [ ] } > ) { }
21
15
}
Original file line number Diff line number Diff line change
1
+ import { Action } from '@ngrx/store' ;
2
+ import { Product } from './model/product' ;
3
+ import { data } from './services/product-data' ;
4
+
5
+ type ProductState = Product [ ] ;
6
+ const initState : ProductState = data ;
7
+
8
+ export function reducer (
9
+ state : ProductState = initState , action : Action ) : ProductState {
10
+ return state ;
11
+ }
You can’t perform that action at this time.
0 commit comments