-
Notifications
You must be signed in to change notification settings - Fork 0
/
minimal.ts
34 lines (29 loc) · 922 Bytes
/
minimal.ts
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
import Base from './base';
import {findPolygon, insertShape, shiftBy} from '../lib';
class Minimal extends Base {
constructor(id, initDoc) {
super(id, initDoc);
}
protected handleMouseDown(cords) {
const shape = findPolygon(this.doc, cords);
if (shape) {
this.dragging = {
shape,
startPos: cords
};
}
return null;
}
protected handleMouseUp(cords) {
if (this.dragging === null) {//Potential source of bugs: explicit state check
return null;
}
const dx = cords.x - this.dragging.startPos.x;
const dy = cords.y - this.dragging.startPos.y;
this.doc = insertShape(this.doc, shiftBy(this.dragging.shape, dx, dy));
// potential bug source: update the internal state
this.dragging = null;
return null;
}
}
export default Minimal;