Issue #2152Opened July 19, 2019by csb3461 reactions

[QUESTION] How to distinguish between a successful or invalid store?

Question

Hi! I'm integrating GrapesJS ina laravel app and so far so good.

After configuring remote load and storage, I'm trying to show a notification after any store (auto or manual).

Following the API documentation I got that easily: editor.on('storage:end:store', () => { showNotification() });

This works fine. Then I tried to show a different notification in case of a remote error like this: editor.on('storage:error:store', () => { showErrorNotification() });

It's working, but in case of an error it shows both the notifications. I think there is no storage:success:store event. Is there any way to achive this with the available events?

Thanks and keep on the excelent work!

Answers (1)

artfJuly 31, 20191 reactions

@csb346 yes, you're right, there is no storage:success:store, the event storage:end:store is correctly called even in case of errors, but being the last called you can make use of a flag variable

let error;
editor.on('storage:error:store', () => {
	showErrorNotification();
	error = 1;
});
editor.on('storage:end:store', () => {
	!error && showNotification();
	error = 0;
});

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.