π The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
Implement debounce
Smaug673971499496c277
diff --git a/frontend/components/MarkdownEditor/MarkdownEditor.vue b/frontend/components/MarkdownEditor/MarkdownEditor.vueindex 47c6d54d..7642d7ed 100644--- a/frontend/components/MarkdownEditor/MarkdownEditor.vue+++ b/frontend/components/MarkdownEditor/MarkdownEditor.vue@@ -30,7 +30,9 @@ const textarea = ref<HTMLTextAreaElement>();const editor = new Editor(textarea, toolbar, container, props.options);const emit = defineEmits(['save', 'exit']);-const update = () => (document.value.content_html = compile(textarea.value?.value || ''));+const update = debounce(() => {+ document.value.content_html = compile(textarea.value?.value || '');+}, 50);const handleClick = () => editor.handleInlineToolbar();const markdownPreview = ref<HTMLDivElement>();@@ -51,6 +53,20 @@ function save() {document.value.content_html = compile(document.value.content_markdown);emit('save', document.value);}++function debounce(fn: Function, wait: number) {+ let timer: NodeJS.Timeout;+ return function (...args: any[]) {+ if (timer) {+ clearTimeout(timer); // clear any pre-existing timer+ }+ // @ts-ignore+ const context = this; // get the current context+ timer = setTimeout(() => {+ fn.apply(context, args); // call the function if time expires+ }, wait);+ };+}</script><style scoped lang="scss">