Recall & Review
beginner
What is an action in the Actions and reducers pattern?
An action is a simple object that describes what happened in the app. It usually has a
type property and may carry extra data called payload.Click to reveal answer
beginner
What role does a reducer play in state management?
A reducer is a pure function that takes the current state and an action, then returns a new state. It decides how the state changes based on the action.
Click to reveal answer
intermediate
Why should reducers be pure functions?
Reducers must be pure to ensure predictable state changes. They should not modify inputs or cause side effects like API calls or random values.
Click to reveal answer
intermediate
How do actions and reducers work together in Angular's state management?
Actions describe events, and reducers listen to these actions to update the state accordingly. This keeps state changes clear and traceable.
Click to reveal answer
advanced
What is a common pattern to organize actions and reducers in Angular apps?
Use
@ngrx/store library to define actions with createAction and reducers with createReducer. This helps keep code clean and maintainable.Click to reveal answer
What does an action object usually contain?
✗ Incorrect
Actions describe what happened with a type and may carry extra data as payload.
What must a reducer function NOT do?
✗ Incorrect
Reducers should never modify the current state directly; they must return a new state object.
In Angular, which library is commonly used for actions and reducers?
✗ Incorrect
@ngrx/store provides tools to define actions and reducers for state management.
What is the main benefit of using actions and reducers?
✗ Incorrect
Actions and reducers make state changes clear and predictable, improving app maintainability.
Which of these is NOT part of the actions and reducers pattern?
✗ Incorrect
Services are separate from the actions and reducers pattern, which focuses on actions, reducers, and state.
Explain how actions and reducers work together to manage state in an Angular app.
Think about how a message (action) tells the app what changed, and the reducer decides how to update the state.
You got /4 concepts.
Describe why reducers must be pure functions and what could go wrong if they are not.
Consider what happens if a function changes data outside itself or depends on random values.
You got /4 concepts.