Skip to content

Commit

Permalink
js: remove consistent_pane_copy
Browse files Browse the repository at this point in the history
  • Loading branch information
David Hartmann authored and JackUrb committed Mar 22, 2023
1 parent 8f697cc commit 87940e7
Showing 1 changed file with 10 additions and 37 deletions.
47 changes: 10 additions & 37 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ function App() {
);

// non-triggering state variables
const consistent_pane_copy = useRef({});
const _bin = useRef(null);
const _socket = useRef(null);
const _timeoutID = useRef(null);
Expand Down Expand Up @@ -129,7 +128,6 @@ function App() {
// ---------------- //
// helper functions //
// ---------------- //
const deepcopy = (obj) => JSON.parse(JSON.stringify(obj));

// append env to pane id for localStorage key
const keyLS = (key) => selection.envID + '_' + key;
Expand Down Expand Up @@ -199,8 +197,6 @@ function App() {
let exists = newPane.id in newPanes;
newPanes[newPane.id] = newPane;

consistent_pane_copy.current[newPane.id] = deepcopy(newPane);

if (!exists) {
let stored = JSON.parse(localStorage.getItem(keyLS(newPane.id)));
if (_bin.current == null) {
Expand Down Expand Up @@ -294,34 +290,17 @@ function App() {
_socket.current = socket;
};

// Apply patch and check hash. Re-fetch if final window doesn't match hash
const _checkWindow = (cmd, numTries) => {
if (cmd.win in consistent_pane_copy.current) {
let windowContent = consistent_pane_copy.current[cmd.win];
let finalWindow = jsonpatch.applyPatch(
windowContent,
// Apply patch or queries window if window to be patched does not exist
const updateWindow = (cmd) => {
if (cmd.win in storeData.panes) {
let modifiedWindow = storeData.panes[cmd.win];
let modifiedFinalWindow = jsonpatch.applyPatch(
modifiedWindow,
cmd.content
).newDocument;
let hashed = md5(stringify(finalWindow));
if (hashed === cmd.finalHash) {
consistent_pane_copy.current[cmd.win] = finalWindow;

let modifiedWindow = storeData.panes[cmd.win];
let modifiedFinalWindow = jsonpatch.applyPatch(
modifiedWindow,
cmd.content
).newDocument;
addPaneBatched(modifiedFinalWindow);
} else {
postForEnv(selection.envIDs);
}
addPaneBatched(modifiedFinalWindow);
} else {
numTries--;
if (numTries) {
setTimeout(_checkWindow, 100, cmd, numTries);
} else {
postForEnv(selection.envIDs);
}
postForEnv(selection.envIDs);
}
};

Expand Down Expand Up @@ -351,9 +330,7 @@ function App() {
if (selection.envIDs.length > 1 && cmd.has_compare !== true) {
postForEnv(selection.envIDs);
} else {
let numTries = 3;
// Check to see if the window exists before trying to update
setTimeout(_checkWindow, 0, cmd, numTries);
updateWindow(cmd);
}
break;
case 'reload':
Expand Down Expand Up @@ -418,9 +395,7 @@ function App() {
return;
}
let newPanes = Object.assign({}, storeData.panes);
let newPanesCopy = Object.assign({}, consistent_pane_copy.current);
delete newPanes[paneID];
delete newPanesCopy[paneID];
if (!keepPosition) {
localStorage.removeItem(keyLS(paneID));

Expand All @@ -437,7 +412,6 @@ function App() {
(paneLayout) => paneLayout.i !== paneID
);

consistent_pane_copy.current = newPanesCopy;
setStoreData((prev) => ({
...prev,
layout: newLayout,
Expand All @@ -456,7 +430,6 @@ function App() {
closePane(paneID, false, false);
});
rebin();
consistent_pane_copy.current = {};
setStoreData((prev) => ({
...prev,
layout: [],
Expand Down Expand Up @@ -587,7 +560,7 @@ function App() {
layoutItem.w == oldLayoutItem.w &&
layoutItem.h == oldLayoutItem.h
) {
let pane = consistent_pane_copy.current[layoutItem.i];
let pane = storeData.panes[layoutItem.i];

// resets to default layout (same as during pane creation)
layoutItem.w = pane.width ? p2w(pane.width) : PANE_SIZE[pane.type][0];
Expand Down

0 comments on commit 87940e7

Please sign in to comment.