use obsidian's builtin debounce

This commit is contained in:
bdeshi committed 2026-08-01 20:27:10 +06:00
1 parent 5f564b5f18
commit 4de8def0bb
1 file changed
+4 -12
+4 -12
View File
@@ -1,20 +1,12 @@
const { Plugin } = require('obsidian'); const { Plugin, debounce } = require('obsidian');
// a bunch of ribbon icons can attach within milliseconds of each other on
// startup, so debounce instead of re-checking the order on every single one
function debounce(fn, wait) {
let timer = null;
return () => {
clearTimeout(timer);
timer = setTimeout(fn, wait);
};
}
module.exports = class RibbonClasp extends Plugin { module.exports = class RibbonClasp extends Plugin {
async onload() { async onload() {
this.settings = Object.assign({ order: [] }, await this.loadData()); this.settings = Object.assign({ order: [] }, await this.loadData());
this.enforcing = false; this.enforcing = false;
this.debouncedEnforce = debounce(() => this.enforceOrder(), 200); // icons can attach within milliseconds of each other on startup
// (resetTimer, or it fires 200ms after the first one instead of the last)
this.debouncedEnforce = debounce(() => this.enforceOrder(), 200, true);
this.app.workspace.onLayoutReady(() => { this.app.workspace.onLayoutReady(() => {
this.patchRibbon(); this.patchRibbon();