mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 16:22:44 +00:00
Add Patch wrapper/unwrapper for saves
Object encapsulation for the win?
This commit is contained in:
@@ -256,12 +256,12 @@ const EditPage = createClass({
|
||||
await updateHistory(this.state.brew).catch(console.error);
|
||||
await versionHistoryGarbageCollection().catch(console.error);
|
||||
|
||||
const preSaveSnapshot = { ...this.state.brew }
|
||||
const preSaveSnapshot = { ...this.state.brew };
|
||||
|
||||
//Prepare content to send to server
|
||||
const brew = { ...this.state.brew };
|
||||
brew.pageCount = ((brew.renderer=='legacy' ? brew.text.match(/\\page/g) : brew.text.match(/^\\page$/gm)) || []).length + 1;
|
||||
brew.patches = makePatches(this.savedBrew.text, brew.text);
|
||||
brew.patches = stringifyPatches(makePatches(this.savedBrew.text, brew.text));
|
||||
brew.hash = await md5(this.savedBrew.text);
|
||||
brew.text = undefined;
|
||||
brew.textBin = undefined;
|
||||
|
||||
@@ -352,11 +352,11 @@ const api = {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
return res.status(409).send(JSON.stringify({ message: `The server copy is out of sync with the saved brew. Please save your changes elsewhere, refresh, and try again.` }));
|
||||
}
|
||||
|
||||
|
||||
let brew = _.assign(brewFromServer, brewFromClient);
|
||||
brew.title = brew.title.trim();
|
||||
brew.description = brew.description.trim() || '';
|
||||
brew.text = applyPatches(brewFromClient.patches, brewFromServer.text)[0];
|
||||
brew.text = applyPatches(parsePatch(brewFromClient.patches), brewFromServer.text)[0];
|
||||
brew.text = api.mergeBrewText(brew);
|
||||
|
||||
const googleId = brew.googleId;
|
||||
|
||||
Reference in New Issue
Block a user