Debounce Feature For GrapesJS Remote storage #5193
SamuelVirgo
started this conversation in
Ideas
Replies: 1 comment
-
store(data, options = {}) {
return new Promise((res, rej) => {
clearTimeout(this.debounceTimer);
this.debounceTimer = setTimeout(async () => {
try {
// store logic...
res();
} catch (error) {
rej(error);
}
}, this.debounceDelay);
});
},
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm building quite a custom implementation on top of grapejs and in a position where I need to be able debounce calls to my backend when running the store & load methods. I tried to build a custom storage manager on top of the grapesjs default remote storage manager but am struggling and can't find enough documentation to help. This is my current implementation:
`const debouncedStoragePlugin = (editor) => {
const { Storage } = editor;
Storage.add('remote-debounced', {
debounceDelay: 500,
debounceTimer: null,
pendingChanges: {},
}`
-> For some reason "data" is always returning as undefined even though I can clearly see it loading correctly in the network tab. Is anyone able to advice why that maybe?
-> I'm not sure how to handle errors in such a way that they trigger the storage:error:load, storage:error:store events. Can anyone advice there?
-> In general is this implementation correct? I tried to base it on the docs although I can't find an example there of implementing the load method or correctly throwing errors. Maybe there is a simpler way of debouncing these changes rather than extending the storage manager like this?
As a general feature request it would be nice to be able to add a debounce rather than a change count to be responsible for triggering the store function.
Beta Was this translation helpful? Give feedback.
All reactions