Created
May 1, 2021 16:38
-
-
Save shabegom/d10af3183d046930ab9d6e8343088f48 to your computer and use it in GitHub Desktop.
listen to an event in obsidian and clean up the listener onunload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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