commit
message
Refactoring use of Errors
author
Ben Vogt <[email protected]>
date
2016-12-29 16:08:00
stats
2 file(s) changed,
27 insertions(+),
24 deletions(-)
files
ts/Errors.ts
ts/Sheet.ts
1diff --git a/ts/Errors.ts b/ts/Errors.ts
2new file mode 100644
3index 0000000..0e6d73a
4--- /dev/null
5+++ b/ts/Errors.ts
6@@ -0,0 +1,23 @@
7+var Errors = {
8+ errors: [
9+ {type: 'NULL', output: '#NULL'},
10+ {type: 'DIV_ZERO', output: '#DIV/0!'},
11+ {type: 'VALUE', output: '#VALUE!'},
12+ {type: 'REF', output: '#REF!'},
13+ {type: 'NAME', output: '#NAME?'},
14+ {type: 'NUM', output: '#NUM!'},
15+ {type: 'NOT_AVAILABLE', output: '#N/A!'},
16+ {type: 'ERROR', output: '#ERROR'}
17+ ],
18+ get: function (type) {
19+ var error = Errors.errors.filter(function (item) {
20+ return item.type === type || item.output === type;
21+ })[0];
22+
23+ return error ? error.output : null;
24+ }
25+};
26+
27+export {
28+ Errors
29+}
30\ No newline at end of file
31diff --git a/ts/Sheet.ts b/ts/Sheet.ts
32index 1559b35..e0622fc 100644
33--- a/ts/Sheet.ts
34+++ b/ts/Sheet.ts
35@@ -2,6 +2,7 @@
36 import { Parser } from "./Parser";
37 import { A1CellKey } from "./A1CellKey"
38 import { Cell } from "./Cell"
39+import { Errors } from "./Errors"
40 import * as Formula from "formulajs"
41
42 var Sheet = (function () {
43@@ -42,27 +43,6 @@ var Sheet = (function () {
44 return newParser;
45 };
46
47- var Exception = {
48- errors: [
49- {type: 'NULL', output: '#NULL'},
50- {type: 'DIV_ZERO', output: '#DIV/0!'},
51- {type: 'VALUE', output: '#VALUE!'},
52- {type: 'REF', output: '#REF!'},
53- {type: 'NAME', output: '#NAME?'},
54- {type: 'NUM', output: '#NUM!'},
55- {type: 'NOT_AVAILABLE', output: '#N/A!'},
56- {type: 'ERROR', output: '#ERROR'}
57- ],
58- get: function (type) {
59- var error = Exception.errors.filter(function (item) {
60- return item.type === type || item.output === type;
61- })[0];
62-
63- return error ? error.output : null;
64- }
65- };
66-
67-
68 class Matrix {
69 public data: Array<Cell>;
70 constructor() {
71@@ -568,17 +548,17 @@ var Sheet = (function () {
72 result = null;
73 deps.forEach(function (id) {
74 // instance.matrix.updateItem(id, {value: null, error: Exception.get('REF')});
75- instance.matrix.getItem(new A1CellKey(id)).setError(Exception.get('REF'));
76+ instance.matrix.getItem(new A1CellKey(id)).setError(Errors.get('REF'));
77 instance.matrix.getItem(new A1CellKey(id)).setValue(null);
78 });
79 throw Error('REF');
80 }
81 } catch (ex) {
82- var message = Exception.get(ex.message);
83+ var message = Errors.get(ex.message);
84 if (message) {
85 error = message;
86 } else {
87- error = Exception.get('ERROR');
88+ error = Errors.get('ERROR');
89 }
90 }
91