initDrawLine: function() {
//start Draging
var moveStart = this.mouseDown
.filter((e) =>!e.altKey && !e.metaKey)
//start Moving
var move = moveStart
.flatMap(() => {
var takeUntil = this.mouseMove.takeUntil(this.mouseUp); // on mouse up stop preview
takeUntil.onEnd(this.endLine.bind(this)); // save line
return takeUntil
});
var endPoint = move.map((e) => this.getNearestPoint(e)) //get end point on mouse move
var startPoint = moveStart.map((e) => {
return this.getNearestPoint(e); //get start point on mouse down
})
var preview = startPoint.combine(endPoint, (start, end) => {
return {
preview: true,
startPoint: start,
previewEndPoint: end
}
})
preview.onValue((state) => this.setState(state)); //draw preview of line with start and end point
},
The problem with the solution of combining the two streams is, that on the begin of the second mouse down the end point stream has still data and a line is drawn from the new start point to the old end point. A