4 ms·
The purpose of `view = fn(state)` is to protect you from O(n*m) complexity scaling if you handle each event in isolation. For any given part of your UI, you'll
by fleabitdev 3y ago
The purpose of `view = fn(state)` is to protect you from O(n*m) complexity scaling if you handle each event in isolation.
For any given part of your UI, you'll have n events to handle ("UI started up for the first time", "x changed", "y changed", "checkbox toggled", "undo", "redo", "file loaded"), and m invariants to uphold ("while the checkbox is checked, the user cannot edit y", "while x is less than y, the UI should display a warning", "this label displays the current value of y as a localised string"). If you try to manually maintain each invariant when handling each event, you'll find it works for simple cases, but it falls apart for larger values of n and m.