Find your next open-source project

Search by name, purpose, or keyword — or paste a GitHub repository URL
All skills

using-kea-disposables

Register timers and event listeners in a kea logic through cache.disposables.add so cleanup runs automatically.

When to use it

You're writing a kea logic that sets up a setInterval, setTimeout, or window listener and you're about to add a matching beforeUnmount to clear it.

For example

You say

In our kea logic I added a setInterval in afterMount that polls team data every 30s, plus a beforeUnmount that clears it. Convert this to use kea disposables so it cleans up on unmount and pauses when the tab is hidden.

You get
  • Updated logic file
  • Removed beforeUnmount block

How it works

  • Named keys let you call dispose(key) to stop a timer or listener early on a state change.
  • pauseOnPageHidden defaults to true; opt out for storage, online/offline, message, or visibilitychange listeners.
  • The disposables builder replaces afterMount for resources that live as long as the logic.