-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.js
64 lines (53 loc) · 1.74 KB
/
model.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"use strict";
const joint = require ('jointjs');
class Model extends joint.shapes.devs.Model {
constructor (frandre) {
super ({
ports: {
groups: {
'in': {
markup: '<path class="port-body" stroke="black" d="M 0,-10 L 0,10 L 16,0 z"/>',
attrs: {
'.port-body': { magnet: 'passive' }
},
label: { position: {
name: 'right',
args: { x: 20, y: 0 }
}}
},
'out': {
markup: '<path class="port-body" stroke="black" d="M 0,-10 L 0,10 L 16,10 L 16,-10 z"/>',
label: { position: 'left' }
}
}
}
});
this.pendingEvents = {};
this.frandre = frandre;
frandre.graph.addCell (this);
}
getStrongDeps (label) { return []; }
handleEvents (evs) { return {}; }
addEvent (label, value) {
if (! this.pendingEvents.hasOwnProperty[label])
this.pendingEvents[label] = [];
this.pendingEvents[label].push (value);
}
bumpEvents () {
const res = this.handleEvents (this.pendingEvents);
this.pendingEvents = {};
return res;
}
causeEvent (label, value) {
this.frandre.currentEvents.push ([this.id, label, value]);
if (! this.frandre.handlingEvents)
this.frandre.processEvents ();
}
setLabel (text) {
this.view ().$el.find ('.label').text (text);
}
view () {
return this.findView (this.frandre.paper);
}
}
module.exports = Model