formula-store
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -52,3 +52,3 @@ "use strict"; | ||
catch (ex) { | ||
fieldGraph.removeNode(node); | ||
removeField(node.id); | ||
throw new errors_1.FormulaFieldCircularDependencyError(node.id); | ||
@@ -79,30 +79,31 @@ } | ||
}; | ||
const removeField = (fieldId) => { | ||
if (!addedFields.has(fieldId)) { | ||
throw new errors_1.FormulaFieldNotFoundError(fieldId); | ||
} | ||
const field = addedFields.get(fieldId); | ||
const fieldToRecalculate = getFieldsToRecalculateOnNodeChanges(field); | ||
addedFields.delete(fieldId); | ||
fieldGraph.removeNode(field); | ||
dependencyTree = fieldGraph.kahnTopologicalSort(); | ||
const changes = []; | ||
for (const dep of dependencyTree) { | ||
const node = fieldToRecalculate.get(dep.id); | ||
if (!node) { | ||
continue; | ||
} | ||
node.value = node.calculate(...node.incomingNeighbors.map(n => { | ||
const field = addedFields.get(n); | ||
return field.value; | ||
})); | ||
changes.push({ | ||
id: node.id, | ||
value: node.value | ||
}); | ||
} | ||
onChange(changes); | ||
return changes.map(c => c.id); | ||
}; | ||
return { | ||
removeField: fieldId => { | ||
if (!addedFields.has(fieldId)) { | ||
throw new errors_1.FormulaFieldNotFoundError(fieldId); | ||
} | ||
const field = addedFields.get(fieldId); | ||
const fieldToRecalculate = getFieldsToRecalculateOnNodeChanges(field); | ||
addedFields.delete(fieldId); | ||
fieldGraph.removeNode(field); | ||
dependencyTree = fieldGraph.kahnTopologicalSort(); | ||
const changes = []; | ||
for (const dep of dependencyTree) { | ||
const node = fieldToRecalculate.get(dep.id); | ||
if (!node) { | ||
continue; | ||
} | ||
node.value = node.calculate(...node.incomingNeighbors.map(n => { | ||
const field = addedFields.get(n); | ||
return field.value; | ||
})); | ||
changes.push({ | ||
id: node.id, | ||
value: node.value | ||
}); | ||
} | ||
onChange(changes); | ||
return changes.map(c => c.id); | ||
}, | ||
removeField, | ||
editField: ({ id, value, dependencies, calculate }) => { | ||
@@ -109,0 +110,0 @@ checkFields(id, dependencies); |
{ | ||
"name": "formula-store", | ||
"description": " A package to handle formula calculations and dependency management", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "types": "lib/index.d.ts", |
Sorry, the diff of this file is not supported yet
289
49778