Excerise: Map Zoom
To begin, checkout the 03-store-exercise branch:
git checkout 03-store-exercise🤫 The solution branch is available if you get stuck.
You can checkout the solution via:
git checkout 03-store-exercise-solutionGoals
- Practice declaring actions.
- Practice declaring a reducer function.
- Practice declaring projector functions and selectors.
- Practice injecting the
Storesingleton instance. - Practice selecting a slice of data from the state object.
Steps
- Create a new directory at src/app/state/map.
- Declare a
SetMapZoomaction in a new file at src/app/state/map/map.actions.ts. - Declare the
reducer()function in a new file at src/app/state/map/map.reducer.ts to update thezoomproperty of the current feature state. - Declare the
getZoomprojector function that returns the value of thezoomproperty. - Update the
Featuresenum in src/app/state/index.ts with a newmapmember. - Update the
Stateinterface and thereducersmap in src/app/state/index.ts. - Create a
mapState()feature selector in src/app/state/index.ts. - Create a
mapZoom()selector in src/app/state/index.ts. - Update the
ResortsMapComponent.zoomproperty to be a component input. This enables us to bind the zoom level of the map from a container component. - Update the
DashboardComponentclass with a newmapZoomproperty. - Update the
DashboardComponent.nOnInit()lifecycle method to select the zoom value in state.
Try it Out
Use the Redux Devtools to dispatch the following action:
{
type: '[Map] Set Zoom',
zoom: 8
}The map zoom level should update based on the zoom value specified.