Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subjects from windowToggle continue forever #5187

Closed
SephVelut opened this issue Dec 20, 2019 · 2 comments
Closed

Subjects from windowToggle continue forever #5187

SephVelut opened this issue Dec 20, 2019 · 2 comments

Comments

@SephVelut
Copy link

SephVelut commented Dec 20, 2019

Bug Report

Current Behavior
Each returned Subject on windowToggle continues forever after closingSelector emits when the closingSelector is a stream from another windowToggle.

Reproduction

// <div id="zone1"><div id="zone2"></div></div>
const zone1 = document.getElementById("zone1") // not null
const zone2 = document.getElementById("zone2") // not null

const zone1Down = fromEvent(zone1, 'mousedown')
const zone1Move = fromEvent(zone1, 'mousemove')
const zone1Up = fromEvent(zone1, 'mouseup')

const zone2Move = fromEvent(zone2, 'mousemove')

const zone1Window = merge(zone1Down, zone1Move, zone1Up)
    .pipe(windowToggle(zone1Down, (_: any) => zone1Up))
    .pipe(share())

const opener = zone1Window
    .pipe(map(s => s.pipe(take(1))) // take the first in each windowed stream
    .pipe(flatMap(e => e))

const closer = zone1Window
    .pipe(map(s => s.pipe(takeLast(1))) // take the last in each windowed stream
    .pipe(flatMap(e => e))

// The issue happens here
zone2Move
   .pipe(windowToggle(opener, (_: any) => closer))
   .pipe(flatMap(e => e))
   .subscribe(console.log)

When the zone1 div is clicked down and held then zone2Move starts emitting movement from zone2 div. All good. Releasing the mouse to activate zone1Up to emit, which causes the closer to emit which should cause the subject emitted by zone2Move to stop emitting, but the subject continues to emit.

Changing the last windowToggle code to this

zone2Move
   .pipe(windowToggle(zone1Down, (_: any) => zone1Up))
   .pipe(flatMap(e => e))
   .subscribe(console.log)

Exhibits the correct behavior. Subjects from zone2Move stop emitting after zone1Up emits. But I don't see the difference between the two windowing methods. zone1Down and opener are emitting the same thing, same time. As are zone1Up and closer. This leads me to believe there is inconsistent behavior with windowToggle

Environment

  • Runtime: Chrome 79.0.3945.79
  • RxJS version: 6.5.3
@cartant
Copy link
Collaborator

cartant commented Jan 25, 2020

Can the example be simplified? I don't understand why the zone1Down, zone1Move and zone1Up observables are merged here. There will be two subscription to the zone1Down: for the source in the merge and for the opening notifier to windowToggle.

Why is this necessary? What behaviour were you expecting to see here?

const zone1Window = merge(zone1Down, zone1Move, zone1Up)
    .pipe(windowToggle(zone1Down, (_: any) => zone1Up))
    .pipe(share())

@cartant
Copy link
Collaborator

cartant commented Apr 30, 2021

Closing this 'cause no simplified reproduction - or explanation - was provided.

@cartant cartant closed this as completed Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants