1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

revoke objectURL of graphs instead of creating a new one

This commit is contained in:
Sonja Happ 2021-01-25 15:37:02 +01:00
parent aa9b8906dd
commit 39af802979

View file

@ -25,19 +25,46 @@ class ICGraphStore extends ArrayStore {
saveGraph(state, action){
let icID = parseInt(action.icid);
const dublicate = state.some(element => element.icID === icID);
if(dublicate){
return state
}
let icGraph = {};
icGraph["icID"] = icID;
icGraph["icID"] = action.icid;
icGraph["data"] = new Blob([action.data.data], {type: action.data.type});
icGraph["type"] = action.data.type;
icGraph["objectURL"] = URL.createObjectURL(icGraph["data"]);
let newElements = [icGraph]
// search for existing element to update
state.forEach((element, index, array) => {
newElements = newElements.filter((updateElement, newIndex) => {
if (element.icID === updateElement.icID) {
console.log("Updating graph:", icGraph.icID)
// update each property
for (var key in updateElement) {
if (updateElement.hasOwnProperty(key) && key === "objectURL") {
URL.revokeObjectURL(array[index][key]);
console.log("revoked objectURL", array[index][key])
} else if (updateElement.hasOwnProperty(key)){
array[index][key] = updateElement[key];
}
}
// remove updated element from update list
return false;
}
return true;
});
});
// all elements still in the list will just be added
state = state.concat(newElements);
// announce change to listeners
this.__emitChange();
return this.updateElements(state, [icGraph]);
return state;
}
reduce(state, action) {