commit
message
[Cell, Sheet] Starting process of refactoring cell internal value storage
author
Ben Vogt <[email protected]>
date
2017-05-10 03:38:08
stats
2 file(s) changed,
18 insertions(+),
7 deletions(-)
files
src/Cell.ts
src/Sheet.ts
1diff --git a/src/Cell.ts b/src/Cell.ts
2index 92baf9c..01b7af3 100644
3--- a/src/Cell.ts
4+++ b/src/Cell.ts
5@@ -105,6 +105,13 @@ class Cell {
6 return this.value;
7 }
8
9+ /**
10+ * CLears a cells value.
11+ */
12+ clearValue() {
13+ this.value = null;
14+ }
15+
16 /**
17 * Set error for this cell. Usually in the case of a parse error when parsing the formula.
18 * @param error to set.
19diff --git a/src/Sheet.ts b/src/Sheet.ts
20index 8c4f627..d8288aa 100644
21--- a/src/Sheet.ts
22+++ b/src/Sheet.ts
23@@ -145,14 +145,14 @@ var Sheet = (function () {
24 /**
25 * Set a cell in this matrix. Could update an existing cell, or add a new one.
26 * @param id to of cell to create of update
27- * @param formula of cell to create or update
28+ * @param rawFormula of cell to create or update
29 */
30- setCell(id: string, formula: string) {
31+ setCell(id: string, rawFormula: string) {
32 var cell = new Cell(id);
33- if (formula.charAt(0) === "=") {
34- cell.setFormula(formula.substr(1));
35+ if (rawFormula.charAt(0) === "=") {
36+ cell.setFormula(rawFormula.substr(1));
37 } else {
38- cell.setValue(formula);
39+ cell.setValue(rawFormula);
40 }
41 registerCellInMatrix(cell);
42 recalculateCellDependencies(cell);
43@@ -183,7 +183,11 @@ var Sheet = (function () {
44 // to avoid double translate formulas, update cell data in parser
45 var parsed = parse(cell.getFormula(), cell.getId());
46
47- instance.matrix.getCell(cell.getId()).setValue(parsed.result);
48+ if (parsed.result === null) {
49+ instance.matrix.getCell(cell.getId()).clearValue();
50+ } else {
51+ instance.matrix.getCell(cell.getId()).setValue(parsed.result);
52+ }
53 instance.matrix.getCell(cell.getId()).setError(parsed.error);
54
55 return parsed;
56@@ -538,7 +542,7 @@ var Sheet = (function () {
57 result = null;
58 deps.forEach(function (id) {
59 instance.matrix.getCell(id).setError(Errors.get('REF'));
60- instance.matrix.getCell(id).setValue(null);
61+ instance.matrix.getCell(id).clearValue();
62 });
63 throw Error('REF');
64 }