What problem does it solve?
Timers, event listeners, and subscriptions created inside kea logic need explicit teardown, and the manual cache.foo = setInterval(...) plus beforeUnmount cleanup pattern is error-prone and keeps background work running in hidden tabs.
Core Features & Use Cases
- Managed resource registration: Register
setInterval, setTimeout, window.addEventListener, MediaQueryList listeners, WebSockets, and observers through cache.disposables.add(setup, key?, options?) with automatic cleanup on unmount.
- Keyed lifecycle control: Use named keys to replace previous registrations or call
cache.disposables.dispose(key) to tear down a resource early on state transitions.
- Visibility-aware pausing: Background work automatically pauses when the tab is hidden and resumes on focus, with an opt-out via
pauseOnPageHidden: false for listeners like storage or visibilitychange.
- Use Case: When adding a polling interval to a kea logic, register it through
cache.disposables.add returning a cleanup function instead of writing a matching beforeUnmount block.
Quick Start
Ask the AI to convert a kea logic that stores a setInterval on cache and clears it in beforeUnmount into the cache.disposables.add pattern with a named key.