Skip to content

Commit 68161ab

Browse files
committed
add root data structures to clean up code
1 parent 61493b8 commit 68161ab

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

lib/DomainNameSystem.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
// A single level of a domain name
3+
4+
const debug = require('debug')('d::domain-tree::DomainNameSystem')
5+
6+
// const TreeData = require('./TreeData')
7+
8+
// module.exports = class DomainNameSystem extends TreeData {
9+
10+
// constructor(parent) {
11+
// super('dns', parent)
12+
// }
13+
14+
// }
15+
16+
module.exports = class DomainNameSystem {
17+
18+
constructor(host) {
19+
debug('new dns', host)
20+
this._host = host
21+
}
22+
23+
}

lib/TreeData.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
// A single tree nodes data
3+
4+
const debug = require('debug')('d::domain-tree::TreeData')
5+
const _ = require('lodash')
6+
7+
8+
module.exports = class TreeData {
9+
10+
constructor(key, parent) {
11+
debug('creating tree data with key', key)
12+
this.key = key
13+
this.data = {}
14+
this.data[key] = {}
15+
this.parent = parent
16+
this.pdk = this.parent.data[key]
17+
}
18+
19+
getKey(key, item){
20+
return this.pdk[item]
21+
}
22+
23+
setKey(key, item, value){
24+
return this.pdk[item] = value
25+
}
26+
27+
get(key, item){
28+
return this.parent.data[key][item]
29+
}
30+
31+
set(key, item, value){
32+
return this.parent.data[key][item] = value
33+
}
34+
35+
}

0 commit comments

Comments
 (0)