spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Cosmetic refactoring
author
Ben Vogt <[email protected]>
date
2016-12-31 22:25:24
stats
2 file(s) changed, 33 insertions(+), 31 deletions(-)
files
README.md
src/Sheet.ts
  1diff --git a/README.md b/README.md
  2index a2ea5d7..0f6e682 100644
  3--- a/README.md
  4+++ b/README.md
  5@@ -4,8 +4,6 @@ TypeScript implementation of a spreadsheet.
  6 ## TODO
  7 Things I should do.
  8 
  9-### Rename anything referencing an "item"
 10-
 11 ### Remove A1CellKey. It is unnecessary.
 12 
 13 ### Write documentation for A1CellKey
 14diff --git a/src/Sheet.ts b/src/Sheet.ts
 15index 9d4525d..cf2a1f9 100644
 16--- a/src/Sheet.ts
 17+++ b/src/Sheet.ts
 18@@ -48,22 +48,22 @@ var Sheet = (function () {
 19     constructor() {
 20       this.data = {};
 21     }
 22-    getItem(key: A1CellKey) {
 23+    getCell(key: A1CellKey) {
 24       return this.data[key.toString()];
 25     }
 26-    addItem(cell: Cell) {
 27+    addCell(cell: Cell) {
 28       var cellId = cell.id;
 29       var key = new A1CellKey(cellId);
 30 
 31       if (!(cellId in this.data)) {
 32         this.data[cellId] = cell;
 33       } else {
 34-        this.getItem(key).updateDependencies(cell.dependencies);
 35-        this.getItem(key).setValue(cell.value);
 36-        this.getItem(key).setError(cell.error);
 37+        this.getCell(key).updateDependencies(cell.dependencies);
 38+        this.getCell(key).setValue(cell.value);
 39+        this.getCell(key).setError(cell.error);
 40       }
 41 
 42-      return this.getItem(new A1CellKey(cellId));
 43+      return this.getCell(new A1CellKey(cellId));
 44     }
 45     getDependencies(id: string) {
 46       var getDependencies = function (id: string) {
 47@@ -95,8 +95,8 @@ var Sheet = (function () {
 48             if (allDependencies.indexOf(refId) === -1) {
 49               allDependencies.push(refId);
 50 
 51-              var item = this.getItem(new A1CellKey(refId));
 52-              if (item.dependencies.length) {
 53+              var cell = this.getCell(new A1CellKey(refId));
 54+              if (cell.dependencies.length) {
 55                 getTotalDependencies(refId);
 56               }
 57             }
 58@@ -126,7 +126,7 @@ var Sheet = (function () {
 59     var allDependencies = instance.matrix.getCellDependencies(cell);
 60 
 61     allDependencies.forEach(function (refId) {
 62-      var currentCell = instance.matrix.getItem(new A1CellKey(refId));
 63+      var currentCell = instance.matrix.getCell(new A1CellKey(refId));
 64       if (currentCell && currentCell.formula) {
 65         calculateCellFormula(currentCell);
 66       }
 67@@ -134,18 +134,18 @@ var Sheet = (function () {
 68   };
 69 
 70   var calculateCellFormula = function (cell: Cell) {
 71-    // to avoid double translate formulas, update item data in parser
 72+    // to avoid double translate formulas, update cell data in parser
 73     var parsed = parse(cell.formula, cell.id);
 74     var key =  new A1CellKey(cell.id);
 75 
 76-    instance.matrix.getItem(key).setValue(parsed.result);
 77-    instance.matrix.getItem(key).setError(parsed.error);
 78+    instance.matrix.getCell(key).setValue(parsed.result);
 79+    instance.matrix.getCell(key).setError(parsed.error);
 80 
 81     return parsed;
 82   };
 83 
 84   var registerCellInMatrix = function (cell: Cell) {
 85-    instance.matrix.addItem(cell);
 86+    instance.matrix.addCell(cell);
 87     if (cell.formula !== null) {
 88       calculateCellFormula(cell);
 89     }
 90@@ -424,25 +424,25 @@ var Sheet = (function () {
 91       throw Error('NAME');
 92     },
 93 
 94-    cellValue: function (cell) {
 95+    cellValue: function (cellId) {
 96       var value,
 97         origin = this,
 98-        item = instance.matrix.getItem(new A1CellKey(cell));
 99+        cell = instance.matrix.getCell(new A1CellKey(cellId));
100 
101       // get value
102-      value = item ? item.value : "0"; // TODO: fix this, it's sloppy.
103+      value = cell ? cell.value : "0"; // TODO: fix this, it's sloppy.
104       //update dependencies
105-      instance.matrix.getItem(new A1CellKey(origin)).updateDependencies([cell]);
106+      instance.matrix.getCell(new A1CellKey(origin)).updateDependencies([cellId]);
107       // check references error
108-      if (item && item.dependencies) {
109-        if (item.dependencies.indexOf(cell) !== -1) {
110+      if (cell && cell.dependencies) {
111+        if (cell.dependencies.indexOf(cellId) !== -1) {
112           throw Error('REF');
113         }
114       }
115 
116       // check if any error occurs
117-      if (item && item.error) {
118-        throw Error(item.error);
119+      if (cell && cell.error) {
120+        throw Error(cell.error);
121       }
122 
123       // return value if is set
124@@ -465,7 +465,7 @@ var Sheet = (function () {
125       var cells = instance.utils.iterateCells.call(this, coordsStart, coordsEnd),
126         result = [];
127       //update dependencies
128-      instance.matrix.getItem(new A1CellKey(origin)).updateDependencies(cells.index);
129+      instance.matrix.getCell(new A1CellKey(origin)).updateDependencies(cells.index);
130 
131       result.push(cells.value);
132       return result;
133@@ -496,9 +496,8 @@ var Sheet = (function () {
134       if (deps.indexOf(key) !== -1) {
135         result = null;
136         deps.forEach(function (id) {
137-          // instance.matrix.updateItem(id, {value: null, error: Exception.get('REF')});
138-          instance.matrix.getItem(new A1CellKey(id)).setError(Errors.get('REF'));
139-          instance.matrix.getItem(new A1CellKey(id)).setValue(null);
140+          instance.matrix.getCell(new A1CellKey(id)).setError(Errors.get('REF'));
141+          instance.matrix.getCell(new A1CellKey(id)).setValue(null);
142         });
143         throw Error('REF');
144       }
145@@ -522,7 +521,7 @@ var Sheet = (function () {
146   };
147 
148   var getCell = function (cellKeyString: string) : Cell {
149-    var cell = instance.matrix.getItem(new A1CellKey(cellKeyString));
150+    var cell = instance.matrix.getCell(new A1CellKey(cellKeyString));
151     if (cell === undefined) {
152       return null;
153     }