Skip to content

Commit

Permalink
update(Monaco.js): support code debounce
Browse files Browse the repository at this point in the history
Signed-off-by: Rohith-Raju <[email protected]>
  • Loading branch information
Rohith-Raju authored and poiana committed Dec 5, 2023
1 parent 3f9f855 commit a0f665b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
32 changes: 0 additions & 32 deletions src/Hooks/UseDebounce.tsx

This file was deleted.

8 changes: 7 additions & 1 deletion src/components/Editor/Monaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ const Monaco = () => {

const originalURL = window.location.origin + window.location.pathname;

//debounce code
let debounce: NodeJS.Timeout;

useEffect(() => {
if (monacoEL) {
setEditor((editor) => {
Expand Down Expand Up @@ -164,7 +167,10 @@ const Monaco = () => {
};
squiggly();
editor?.getModel().onDidChangeContent(() => {
dispatch(autosave(editor.getModel().getValue()));
if (debounce) clearTimeout(debounce);
debounce = setTimeout(() => {
dispatch(autosave(editor.getModel().getValue()));
}, 500);
});
return <Editor className="monaco" ref={monacoEL} />;
};
Expand Down

0 comments on commit a0f665b

Please sign in to comment.