obsidian-plugin-events
Installation
SKILL.md
Obsidian Plugin Events
This skill guides you through event handling and resource cleanup in Obsidian plugins. It focuses on the registration system that keeps plugins memory-safe: listening to Obsidian events, DOM events, intervals, scope events, and custom cleanup callbacks.
When to Use This Skill
- Adding event listeners to vault files, workspace layout, or editor changes
- Registering DOM event listeners that must be removed on plugin unload
- Setting up timers with
setIntervalthat need automatic cancellation - Handling keyboard events via Obsidian's scope system
- Preventing memory leaks by cleaning up resources properly
- Understanding the
Componentlifecycle and registration methods
Overview
Obsidian's plugin system is built on the Component class, which provides a registration-based resource management model. When you register a resource through this.register...() methods inside a plugin, it is automatically cleaned up when the plugin unloads. This prevents the most common source of plugin bugs: leaking event listeners, DOM nodes, and timers after the plugin is disabled.
At minimum, every plugin that reacts to the outside world needs: