tracer.js 1.6 KB
Newer Older
N
nem035 已提交
1
const {
J
Jason Park 已提交
2 3
  toJSON,
  fromJSON
4
} = require('../../tracer_manager/util/index');
N
nem035 已提交
5

J
Jason Park 已提交
6
function Tracer(name) {
J
Jason Park 已提交
7 8 9 10 11
  this.module = this.constructor;
  this.capsule = this.manager.allocate(this);
  $.extend(this, this.capsule);
  this.setName(name);
  return this.isNew;
J
Jason Park 已提交
12
}
J
Jason Park 已提交
13

J
Jason Park 已提交
14
Tracer.prototype = {
N
nem035 已提交
15

J
Jason Park 已提交
16 17 18
  constructor: Tracer,
  name: 'Tracer',
  manager: null,
N
nem035 已提交
19

J
Jason Park 已提交
20 21 22 23 24 25 26
  _setData(...args) {
    this.manager.pushStep(this.capsule, {
      type: 'setData',
      args: toJSON(args)
    });
    return this;
  },
N
nem035 已提交
27

J
Jason Park 已提交
28 29 30 31 32 33
  _clear() {
    this.manager.pushStep(this.capsule, {
      type: 'clear'
    });
    return this;
  },
N
nem035 已提交
34

J
Jason Park 已提交
35 36 37 38
  _wait() {
    this.manager.newStep();
    return this;
  },
N
nem035 已提交
39

J
Jason Park 已提交
40 41 42 43 44
  processStep(step, options) {
    const {
      type,
      args
    } = step;
N
nem035 已提交
45

J
Jason Park 已提交
46 47 48 49 50 51 52 53 54
    switch (type) {
      case 'setData':
        this.setData(...fromJSON(args));
        break;
      case 'clear':
        this.clear();
        break;
    }
  },
N
nem035 已提交
55

J
Jason Park 已提交
56 57 58 59 60 61 62 63 64 65
  setName(name) {
    let $name;
    if (this.isNew) {
      $name = $('<span class="name">');
      this.$container.append($name);
    } else {
      $name = this.$container.find('span.name');
    }
    $name.text(name || this.defaultName);
  },
N
nem035 已提交
66

J
Jason Park 已提交
67 68 69 70 71 72 73 74 75
  setData() {
    const data = toJSON(arguments);
    if (!this.isNew && this.lastData === data) {
      return true;
    }
    this.isNew = this.capsule.isNew = false;
    this.lastData = this.capsule.lastData = data;
    return false;
  },
N
nem035 已提交
76

J
Jason Park 已提交
77 78 79 80 81 82
  resize() {
  },
  refresh() {
  },
  clear() {
  },
N
nem035 已提交
83

J
Jason Park 已提交
84 85 86 87 88 89
  attach(tracer) {
    if (tracer.module === LogTracer) {
      this.logTracer = tracer;
    }
    return this;
  },
N
nem035 已提交
90

J
Jason Park 已提交
91 92 93 94 95 96 97 98
  mousedown(e) {
  },
  mousemove(e) {
  },
  mouseup(e) {
  },
  mousewheel(e) {
  }
N
nem035 已提交
99 100 101
};

module.exports = Tracer;