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-solution
Goals
- Practice declaring actions.
- Practice declaring a reducer function.
- Practice declaring projector functions and selectors.
- Practice injecting the
Store
singleton instance. - Practice selecting a slice of data from the state object.
Steps
- Create a new directory at src/app/state/map.
- Declare a
SetMapZoom
action 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 thezoom
property of the current feature state. - Declare the
getZoom
projector function that returns the value of thezoom
property. - Update the
Features
enum in src/app/state/index.ts with a newmap
member. - Update the
State
interface and thereducers
map 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.zoom
property to be a component input. This enables us to bind the zoom level of the map from a container component. - Update the
DashboardComponent
class with a newmapZoom
property. - 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.