Skip to content

Commit 1bda61e

Browse files
author
Pietro Grandi
committed
one reducer
1 parent dab6463 commit 1bda61e

File tree

3 files changed

+18
-33
lines changed

3 files changed

+18
-33
lines changed

app/app.component.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@ import {Observable} from "rxjs/Rx";
44
import {ProximitySelector} from "./components/proximity-selector.component";
55
import {SearchBox} from "./components/search-box.component";
66
import {searchReducer} from "./reducers/search.reducer";
7-
import {locationReducer} from "./reducers/location.reducer";
87
import {CurrentSearch} from "./models/current-search.model";
98

10-
const mainReducer = combineReducers({
11-
searchByName: searchReducer,
12-
searchByLocation: locationReducer
13-
});
14-
159
@Component({
1610
selector: 'my-app',
1711
providers: [
18-
provideStore({ currentSearch: mainReducer })
12+
provideStore({ currentSearch: searchReducer })
1913
],
2014
directives: [ SearchBox, ProximitySelector ],
2115
template: `

app/reducers/location.reducer.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

app/reducers/search.reducer.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
11
import { ActionReducer, Action } from '@ngrx/store';
22
import {CurrentSearch} from "../models/current-search.model";
33
import {SearchBox} from "../components/search-box.component";
4+
import {ProximitySelector} from "../components/proximity-selector.component";
45

56
export const searchReducer: ActionReducer<CurrentSearch> = (state: CurrentSearch, action: Action) => {
67
switch (action.type) {
78
case SearchBox.StoreEvents.text:
89
return Object.assign({}, state, {
910
text: action.payload.text
1011
});
12+
case ProximitySelector.StoreEvents.position:
13+
return Object.assign({}, state, {
14+
position: {
15+
latitude: action.payload.position.latitude,
16+
longitude: action.payload.position.longitude
17+
}
18+
});
19+
case ProximitySelector.StoreEvents.off:
20+
return Object.assign({}, state, {
21+
position: null,
22+
radius: null
23+
});
24+
case ProximitySelector.StoreEvents.radius:
25+
return Object.assign({}, state, {
26+
radius: action.payload.radius
27+
});
1128
default:
1229
return state;
1330
}

0 commit comments

Comments
 (0)