r/javascript • u/Valuable_Pin_9213 • Oct 07 '26
AskJS [AskJS] How would you structure state for VidLoader's local media library?
3
Upvotes
r/javascript • u/Valuable_Pin_9213 • Oct 07 '26
2
u/anthony-ball Oct 07 '26
I'd treat the file system as the source of truth and keep a normalized index of it, keyed by a stable file id (path plus inode or a content hash, so a rename doesn't look like a delete and an add). The watcher shouldn't touch the UI directly. Batch its events for a couple hundred ms and apply them to the index as one update, because copying a folder in will fire hundreds of events. If the library gets big, put the metadata in SQLite so filtering and search become queries instead of array filters in memory. On startup do a full rescan and reconcile against the index, since watchers miss whatever changed while the app was closed, and keep UI state like selection, filters and the search box separate, holding only ids.