Homework
Homework — your search
Homework — your search.
- Add a search field to
index.html(<input type="search" id="search">). - Add
debouncetoutils.jsand wrap the input listener with it inmain.js. AddsearchQueryandvisiblePictures(). - Check filtering. Type text — the grid narrows; clear it — everything returns; type something absent — "No pictures match…".
- Measure debounce. Put
console.count('render')inrender(). With debounce, typing "andromeda" shows ~1 "render"; without it — ~9. That's debounce's payoff in numbers. - Extra: make the search match the
explanationtoo, not just the title.
Required tests:
- Filter test: search narrows the grid, an empty result shows a message.
- Debounce test:
console.countconfirms one render with debounce, not one per keystroke.
To submit: screenshots: (1) the filtered grid, (2) console.count with/without debounce (the difference in numbers).
Next. We have four loose variables and one view. In lesson 8 — the breaking point. When the same data is needed by THREE views, and there are ten variables, "don't forget to re-render them all" becomes an impossible discipline. We'll feel that pain — and only then understand what the pub/sub in lesson 9 solves.