use obsidian's builtin debounce
This commit is contained in:
1 parent
5f564b5f18
commit
4de8def0bb
1 file changed
+4
-12
@@ -1,20 +1,12 @@
|
||||
const { Plugin } = 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);
|
||||
};
|
||||
}
|
||||
const { Plugin, debounce } = require('obsidian');
|
||||
|
||||
module.exports = class RibbonClasp extends Plugin {
|
||||
async onload() {
|
||||
this.settings = Object.assign({ order: [] }, await this.loadData());
|
||||
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.patchRibbon();
|
||||
|
||||
Reference in new issue
Block a user