Skip to content

Possible bug: can no longer merge and takeUntil on the same stream #1360

@bgerm

Description

@bgerm

In RxJS 4 the code below would print 'up' and return to 0, 0 upon releasing the mouse from a drag. In RxJS 5 this is no longer happens.

var box = document.getElementById('box');

var mouseDown = Rx.Observable.fromEvent(document, 'mousedown');
var mouseUp = Rx.Observable.fromEvent(document, 'mouseup');
var mouseMove = Rx.Observable.fromEvent(document, 'mousemove');

var mouseDrag = mouseDown.flatMap(function(md){
  var startX = md.offsetX;
  var startY = md.offsetY;

  return mouseMove
    .merge(mouseUp.map(x => 'up')) // <----
    .map(function(mm){
      if (mm === 'up') {
        console.log('up'); // to show it's no longer hit
        return {
          left: 0,
          top: 0
        };
      }
      return {
        left: mm.clientX - startX,
        top: mm.clientY - startY
      };
    }).takeUntil(mouseUp); // <----
});


mouseDrag.subscribe(function(e){
  box.style.top = e.top + 'px';
  box.style.left = e.left + 'px';
});

RxJS 4 jsbin: https://jsbin.com/cigirovohe/1/edit?html,js,console,output
RxJS 5 jsbin: https://jsbin.com/metosonayi/1/edit?html,js,console,output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions