1
1
import { Component , OnInit } from '@angular/core' ;
2
- import { Store , provideStore , combineReducers } from "@ngrx/store" ;
2
+ import { Store , provideStore } from "@ngrx/store" ;
3
3
import { Observable } from "rxjs/Rx" ;
4
+ import { CurrentSearch } from "./models/current-search.model" ;
4
5
import { ProximitySelector } from "./components/proximity-selector.component" ;
5
6
import { SearchBox } from "./components/search-box.component" ;
6
- import { searchReducer } from "./reducers/search.reducer" ;
7
- import { CurrentSearch } from "./models/current-search.model" ;
7
+ import { SearchReducer } from "./reducers/search.reducer" ;
8
+
9
+ const storeManager = provideStore ( { currentSearch : SearchReducer } ) ;
8
10
9
11
@Component ( {
10
12
selector : 'my-app' ,
11
- providers : [
12
- provideStore ( { currentSearch : searchReducer } )
13
- ] ,
13
+ providers : [ storeManager ] ,
14
14
directives : [ SearchBox , ProximitySelector ] ,
15
15
template : `
16
16
<h1>{{title}}</h1>
17
17
<div class="row">
18
18
<search-box [store]="store"></search-box>
19
19
<proximity-selector [store]="store"></proximity-selector>
20
20
</div>
21
- <div class="row">
22
- <courses-list [searchResults]="results"></courses-list>
23
- </div>
21
+ <p>{{ state | json }}</p>
24
22
`
25
23
} )
26
24
27
25
export class AppComponent implements OnInit {
28
26
29
- title = 'One Source of Truth for Angular 2' ;
27
+ title = 'heroes and books' ; //One Source of Truth for Angular 2';
28
+
29
+ private state : CurrentSearch ;
30
30
31
31
private currentSearch : Observable < CurrentSearch > ;
32
32
@@ -38,8 +38,7 @@ export class AppComponent implements OnInit {
38
38
39
39
ngOnInit ( ) {
40
40
this . currentSearch . subscribe ( ( state : CurrentSearch ) => {
41
- // the logic is here
42
- console . log ( state ) ;
41
+ this . state = state ;
43
42
} ) ;
44
43
}
45
44
0 commit comments