# all files / clique/util/ MultiTable.js

68.89% Statements 31/45
57.14% Branches 12/21
50% Functions 6/12
17.65% Lines 3/17
9 statements, 2 functions, 7 branches Ignored

    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
    43
    441×
    1×

     export default class MultiTable {
      constructor () {
        this.table = {};
      }

      add (key, item) {
        let table = this.table;

        if (!table.hasOwnProperty(key)) {
          table[key] = new Set();
        }

        table[key].add(item);
      }

      remove (key, item) {
        let table = this.table;

        if (table.hasOwnProperty(key)) {
          table[key].delete(item);
        }
      }

      strike (key) {
        delete this.table[key];
      }

      has (key, item) {
        let table = this.table;

        return table.hasOwnProperty(key) && (item === undefined || table[key].has(item));
      }

      items (key) {
        let table = this.table;

        if (table.hasOwnProperty(key)) {
          return [...table[key].values()];
        }
      }
    }