commit
message
[Cell, Sheet] First step in process of cleaning up Cell.value
author
Ben Vogt <[email protected]>
date
2017-05-10 03:46:37
stats
2 file(s) changed,
22 insertions(+),
7 deletions(-)
files
src/Cell.ts
src/Sheet.ts
1diff --git a/src/Cell.ts b/src/Cell.ts
2index 01b7af3..fe5f092 100644
3--- a/src/Cell.ts
4+++ b/src/Cell.ts
5@@ -19,7 +19,7 @@ class Cell {
6 var key = parseKey(id);
7
8 this.formula = null;
9- this.value = "";
10+ this.value = null;
11 this.dependencies = [];
12 this.error = null;
13 this.id = id;
14@@ -97,6 +97,19 @@ class Cell {
15 this.value = value;
16 }
17
18+ /**
19+ * Sets the value or formula for this cell. If the input begins with =, then it is considered to be a formula. If it
20+ * is not, then it is a value, and set as the raw value for this cell.
21+ * @param rawFormula
22+ */
23+ setRawFormula(rawFormula: string) {
24+ if (rawFormula.charAt(0) === "=") {
25+ this.formula = rawFormula.substr(1);
26+ } else {
27+ this.value = rawFormula;
28+ }
29+ }
30+
31 /**
32 * Get the value of this cell. Since value could be null do to an error in the formula, this could return null.
33 * @returns {string}
34diff --git a/src/Sheet.ts b/src/Sheet.ts
35index d8288aa..40927f7 100644
36--- a/src/Sheet.ts
37+++ b/src/Sheet.ts
38@@ -88,7 +88,12 @@ var Sheet = (function () {
39 this.data[cellId] = cell;
40 } else {
41 this.getCell(cellId).updateDependencies(cell.getDependencies());
42- this.getCell(cellId).setValue(cell.getValue());
43+ var cellValue = cell.getValue();
44+ if (cellValue === null) {
45+ this.getCell(cellId).clearValue();
46+ } else {
47+ this.getCell(cellId).setValue(cellValue);
48+ }
49 this.getCell(cellId).setError(cell.getError());
50 }
51
52@@ -149,11 +154,7 @@ var Sheet = (function () {
53 */
54 setCell(id: string, rawFormula: string) {
55 var cell = new Cell(id);
56- if (rawFormula.charAt(0) === "=") {
57- cell.setFormula(rawFormula.substr(1));
58- } else {
59- cell.setValue(rawFormula);
60- }
61+ cell.setRawFormula(rawFormula);
62 registerCellInMatrix(cell);
63 recalculateCellDependencies(cell);
64 }