Editor.js: 馃挕Debounce the onChange callback

Created on 16 Jul 2020  路  10Comments  路  Source: codex-team/editor.js

How can I debounce the onChange callback.
I would like to autosave the content from the editor, but I would like to wait a few seconds before the autosave.

I have created a pull request here https://github.com/codex-team/editor.js/pull/1222

feature

Most helpful comment

Why not just debounce on your handler's side?

All 10 comments

Why not just debounce on your handler's side?

@neSpecc I would like to handle the debounce because I am saving the Editor data to Firebase, so I want to limit the number of times the updates are made to a document when the user interacts with the editor.

So If I try the approach you are suggesting all the keyups are being registered and called which causes multiple writes to Firebase

@neSpecc so if I debounce my handler all the key/up/down will cause my debounced handler to be called multiple times and there is no way to delay that even if I would debounce the handler, it will still be registered multiple times when the editor changes which is not a deboune-able event.

I am not sure If I am making sense

all the keyups are being registered and called which causes multiple writes to Firebase

Why? If you'll add a debounce at your onChange handler, you won't save data multiple times.

@neSpecc I am not sure how to achieve that, would you please assist me, maybe show an example

const editor = new EditorJS({
    // Other configuration properties
    onChange: _.debounce(mySaveFunction, 200);
});

@sis-dk what happens if mySaveFunction is async?

@Teebo Doesn't matter. Its autosave right? You can just keep saving from mySaveFunction. Editor doesn't have to wait for the save to finish.

@sis-dk I will try that out, thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tiotdev picture tiotdev  路  3Comments

sei-jdshimkoski picture sei-jdshimkoski  路  5Comments

davedbase picture davedbase  路  3Comments

neSpecc picture neSpecc  路  4Comments

vincentdesmares picture vincentdesmares  路  3Comments