|
12 | 12 |
|
13 | 13 | class Documentation {
|
14 | 14 | _props: Object;
|
15 |
| - _description: string; |
16 | 15 | _composes: Array<string>;
|
| 16 | + _data: Object; |
17 | 17 |
|
18 | 18 | constructor() {
|
19 |
| - this._props = {}; |
20 |
| - this._description = ''; |
21 |
| - this._composes = []; |
| 19 | + this._props = new Map(); |
| 20 | + this._composes = new Set(); |
| 21 | + this._data = new Map(); |
22 | 22 | }
|
23 | 23 |
|
24 | 24 | addComposes(moduleName: string) {
|
25 |
| - if (this._composes.indexOf(moduleName) === -1) { |
26 |
| - this._composes.push(moduleName); |
27 |
| - } |
| 25 | + this._composes.add(moduleName); |
28 | 26 | }
|
29 | 27 |
|
30 |
| - getDescription(): string { |
31 |
| - return this._description; |
| 28 | + set(key: string, value: any) { |
| 29 | + this._data.set(key, value); |
32 | 30 | }
|
33 | 31 |
|
34 |
| - setDescription(description: string): void { |
35 |
| - this._description = description; |
| 32 | + get(key: string) { |
| 33 | + return this._data.get(key); |
36 | 34 | }
|
37 | 35 |
|
38 | 36 | getPropDescriptor(propName: string): PropDescriptor {
|
39 |
| - var propDescriptor = this._props[propName]; |
| 37 | + var propDescriptor = this._props.get(propName); |
40 | 38 | if (!propDescriptor) {
|
41 |
| - propDescriptor = this._props[propName] = {}; |
| 39 | + this._props.set(propName, propDescriptor = {}); |
42 | 40 | }
|
43 | 41 | return propDescriptor;
|
44 | 42 | }
|
45 | 43 |
|
46 | 44 | toObject(): Object {
|
47 |
| - var obj = { |
48 |
| - description: this._description, |
49 |
| - props: this._props, |
50 |
| - }; |
| 45 | + var obj = {}; |
| 46 | + |
| 47 | + for (var [key, value] of this._data) { |
| 48 | + obj[key] = value; |
| 49 | + } |
| 50 | + |
| 51 | + if (this._props.size > 0) { |
| 52 | + obj.props = {}; |
| 53 | + for (var [name, descriptor] of this._props) { |
| 54 | + obj.props[name] = descriptor; |
| 55 | + } |
| 56 | + } |
51 | 57 |
|
52 |
| - if (this._composes.length) { |
53 |
| - obj.composes = this._composes; |
| 58 | + if (this._composes.size > 0) { |
| 59 | + obj.composes = Array.from(this._composes); |
54 | 60 | }
|
55 | 61 | return obj;
|
56 | 62 | }
|
|
0 commit comments