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:
parent
aa9b8906dd
commit
39af802979
1 changed files with 35 additions and 8 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue