mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-13 19:32:45 +00:00
Add comments to elucidate the madness
This commit is contained in:
@@ -67,24 +67,30 @@ export function updateHistory(brew) {
|
|||||||
history[i] = getVersionBySlot(brew, i);
|
history[i] = getVersionBySlot(brew, i);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Walk each version position
|
||||||
numbers.toReversed().every((slot)=>{
|
numbers.toReversed().every((slot)=>{
|
||||||
const storedVersion = history[slot];
|
const storedVersion = history[slot];
|
||||||
|
|
||||||
// If slot has expired, update
|
// If slot has expired, update all lower slots and break
|
||||||
if(new Date() >= new Date(storedVersion.expireAt)){
|
if(new Date() >= new Date(storedVersion.expireAt)){
|
||||||
const keys = Array.from(Array(slot - 1).keys());
|
const slots = Array.from(Array(slot - 1).keys());
|
||||||
keys.toReversed().every((n)=>{
|
slots.toReversed().every((slot)=>{
|
||||||
const num = n + 1;
|
const actualSlot = slot + 1;
|
||||||
updateStoredBrew({ ...history[num], shareId: brew.shareId }, num + 1);
|
// Move data from actualSlot to actualSlot + 1
|
||||||
if(num == 1) {
|
updateStoredBrew({ ...history[actualSlot], shareId: brew.shareId }, actualSlot + 1);
|
||||||
|
// If first slot, fill with current data
|
||||||
|
if(actualSlot == 1) {
|
||||||
updateStoredBrew(brew, 1);
|
updateStoredBrew(brew, 1);
|
||||||
|
// Break after updating first slot
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// Continue loop to move data in remaining slots
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
// Break out of data checks because we found an expired value
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// Continue data checks because this one wasn't expired
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user