Performance: Actions and reducers pattern
MEDIUM IMPACT
This pattern affects how state changes trigger UI updates and how efficiently Angular processes those changes during user interactions.
const reducer = (state, action) => { switch(action.type) { case 'UPDATE': return { ...state, data: action.payload }; default: return state; } };
const reducer = (state, action) => { switch(action.type) { case 'UPDATE': // heavy computation or deep cloning const newState = JSON.parse(JSON.stringify(state)); newState.data = action.payload; return newState; default: return state; } };
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy deep cloning in reducers | Triggers full component tree checks | Multiple reflows if many bindings update | High paint cost due to many DOM updates | [X] Bad |
| Shallow state updates with OnPush | Minimal DOM updates, only changed components | Single reflow per update | Low paint cost | [OK] Good |