Skip to content

Instantly share code, notes, and snippets.

@shabegom
Created May 1, 2021 16:38
Show Gist options
  • Save shabegom/d10af3183d046930ab9d6e8343088f48 to your computer and use it in GitHub Desktop.
Save shabegom/d10af3183d046930ab9d6e8343088f48 to your computer and use it in GitHub Desktop.
listen to an event in obsidian and clean up the listener onunload
// In this example I'm listening to an event in metadataCache.
class MyPlugin extends Plugin {
private eventRef: EventRef
async onload(): Promise<void> {
this.eventRef = this.app.metadataCache.on("changed", (file: Tfile) => doStuff(file))
}
onunload(): void {
this.app.metadataCache.offref(this.eventRef)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment