Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
addMiddleware([SAVING_REVISION], ({ store, next, action }) => {
next(action);
const data: Object = getPage(store.getState());
if (data.locked) {
return;
}
// Construct page payload
const revision = pick(data, ["title", "snippet", "url", "settings"]);
revision.content = data.content.present;
revision.category = data.category.id;
// Check if API call is necessary
if (!dataChanged(revision)) {
return;
}
lastSavedRevision = revision;
state => ({ page: omit(getPage(state), ["content"]) }),
null,
state => ({ page: omit(getPage(state), ["content"]) }),
{ deactivatePlugin, updateRevision }
state => ({ page: omit(getPage(state), ["content"]) }),
null,
state => ({ page: omit(getPage(state), ["content"]) }),
null,
const stateToProps = state => ({
rootElement: state.elements[getContent(state).id],
layout: get(getPage(state), "settings.general.layout"),
renderLayout: isPluginActive("pb-editor-toolbar-preview")(state)
});
state => {
const { title, version, locked, category } = getPage(state);
return {
pageTitle: title,
pageVersion: version,
pageLocked: locked,
pageCategory: category.name,
pageCategoryUrl: category.url
};
},
{ updateRevision }
({ store, next, action }) => {
next(action);
const { onFinish } = action.meta || {};
if (action.type === UPDATE_ELEMENT && action.payload.history === false) {
return;
}
const page = getPage(store.getState());
if (page.locked) {
return;
}
if (debouncedSave) {
debouncedSave.cancel();
}
debouncedSave = debounce(() => store.dispatch(saveRevision(null, { onFinish })), 1000);
debouncedSave();
}
);