summaryrefslogtreecommitdiff
path: root/maize-maze/js/json-ds.js
blob: feb0622522c1c26571bb04bec3d79055db5b0ab1 (plain)
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
// If I were to rewrite this, I would use IEFE's - Dean was right about OO in JS
class JSONSet {
  items = new Set();
  constructor(initial){
    if (initial) {
      this.apply_set_function('add', initial);
    }
  }
  apply_set_function(f_name, x) {
    return this.items[f_name](JSON.stringify(x));
  }
}

class JSONHash {
  items = {};
  constructor(initial_key, initial_value){
    if (initial_key && initial_value) {
      this.items[JSON.stringify(initial)] = initial_value;
    }
  }
  set_value(key, value) {
    this.items[JSON.stringify(key)] = value;
  }
  get_value(key) {
    return this.items[JSON.stringify(key)];
  }
  delete_value(key) {
    delete this.items[JSON.stringify(key)];
  }
}