-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathcollection.js
42 lines (36 loc) · 843 Bytes
/
collection.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Represents unions.
* (A1, A1:C5, ...)
*/
class Collection {
constructor(data, refs) {
if (data == null && refs == null) {
this._data = [];
this._refs = [];
} else {
if (data.length !== refs.length)
throw Error('Collection: data length should match references length.');
this._data = data;
this._refs = refs;
}
}
get data() {
return this._data;
}
get refs() {
return this._refs;
}
get length() {
return this._data.length;
}
/**
* Add data and references to this collection.
* @param {{}} obj - data
* @param {{}} ref - reference
*/
add(obj, ref) {
this._data.push(obj);
this._refs.push(ref);
}
}
module.exports = Collection;