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

Fix window when don t signal on complete #7152

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file not shown.
1 change: 1 addition & 0 deletions docs_app/src/assets/images/marble-diagrams/windowWhen.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions docs_app/tools/marbles/diagrams/windowWhen.txt
@@ -0,0 +1,20 @@
[styles]
event_radius = 33
operator_height = 60
completion_height = 80

---a---b---c---d---e---f---g---h---|

-------------x|
-------------x|
-------------x|

> windowWhen()

x = ---a---b---c-|

y = --d---e---f---g|

z = -g---h---|

x------------y------------z--------|
38 changes: 18 additions & 20 deletions spec/operators/windowWhen-spec.ts
Expand Up @@ -13,21 +13,21 @@ describe('windowWhen', () => {

it('should emit windows that close and reopen', () => {
rxTestScheduler.run(({ hot, cold, expectObservable, expectSubscriptions }) => {
const e2 = cold(' -----------| ');
// -----------|
// -----------|
const e2 = cold(' -----------x| ');
// -----------x|
// -----------x|
const e2subs = [
' ^----------! ',
' -----------^----------! ',
' ----------------------^----!',
' ^----------! ',
' -----------^----------! ',
' ----------------------^----!',
];
const e1 = hot(' --a--^--b--c--d--e--f--g--h--i--|');
const e1subs = ' ^--------------------------!';
const expected = ' a----------b----------c----|';
const e1 = hot('--a--^--b--c--d--e--f--g--h--i--|');
const e1subs = ' ^--------------------------!';
const expected = ' a----------b----------c----|';

const a = cold(' ---b--c--d-| ');
const b = cold(' -e--f--g--h| ');
const c = cold(' --i--|');
const a = cold(' ---b--c--d-| ');
const b = cold(' -e--f--g--h| ');
const c = cold(' --i--|');
const values = { a: a, b: b, c: c };

const source = e1.pipe(windowWhen(() => e2));
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('windowWhen', () => {
});
});

it('should emit windows using varying empty delayed closings', () => {
it('should not emit windows using varying empty delayed closings', () => {
rxTestScheduler.run(({ hot, cold, expectObservable, expectSubscriptions }) => {
const closings = [
cold(' -----------------| '),
Expand All @@ -111,17 +111,15 @@ describe('windowWhen', () => {
];
const closeSubs = [
' ^----------------! ',
' -----------------^----! ',
' ----------------------^------------! ',
' ',
' ',
];
const e1 = hot('--a--^---b---c---d---e---f---g---h------| ');
const e1subs = ' ^----------------------------------! ';
const expected = ' x----------------y----z------------| ';
const expected = ' x----------------------------------| ';

const x = cold(' ----b---c---d---e| ');
const y = cold(' ---f-| ');
const z = cold(' --g---h------| ');
const values = { x: x, y: y, z: z };
const x = cold(' ----b---c---d---e---f---g---h------| ');
const values = { x: x };

let i = 0;
const result = e1.pipe(windowWhen(() => closings[i++]));
Expand Down
24 changes: 14 additions & 10 deletions src/internal/operators/windowWhen.ts
Expand Up @@ -5,6 +5,7 @@ import { ObservableInput, OperatorFunction } from '../types';
import { operate } from '../util/lift';
import { createOperatorSubscriber } from './OperatorSubscriber';
import { innerFrom } from '../observable/innerFrom';
import { noop } from '../util/noop';

/**
* Branch out the source Observable values as a nested Observable using a
Expand All @@ -14,13 +15,15 @@ import { innerFrom } from '../observable/innerFrom';
* <span class="informal">It's like {@link bufferWhen}, but emits a nested
* Observable instead of an array.</span>
*
* ![](windowWhen.png)
* ![](windowWhen.svg)
*
* Returns an Observable that emits windows of items it collects from the source
* Observable. The output Observable emits connected, non-overlapping windows.
* It emits the current window and opens a new one whenever the Observable
* produced by the specified `closingSelector` function emits an item. The first
* window is opened immediately when subscribing to the output Observable.
* Returns an Observable that emits Observable windows of items it collects from
* the source Observable. The output Observable emits connected, non-overlapping
* windows. It emits the current window immediately when subscribing to the source
* Observable and opens a new one whenever the Observable produced by the specified
* `closingSelector` function emits `next`. When an Observable returned by the
* `closingSelector` emits `next`, the previous window completes and a new window
* is emitted to the output subscriber.
*
* ## Example
*
Expand All @@ -44,9 +47,10 @@ import { innerFrom } from '../observable/innerFrom';
* @see {@link windowToggle}
* @see {@link bufferWhen}
*
* @param {function(): Observable} closingSelector A function that takes no
* arguments and returns an Observable that signals (on either `next` or
* `complete`) when to close the previous window and start a new one.
* @param closingSelector A function that takes no arguments and returns an
* {@link ObservableInput} (that gets converted to Observable) that signals
* when to close the previous window and start a new one. Note that a value (any value) must be
* observed to signal window closure.
* @return A function that returns an Observable of windows, which in turn are
* Observables.
*/
Expand Down Expand Up @@ -95,7 +99,7 @@ export function windowWhen<T>(closingSelector: () => ObservableInput<any>): Oper
// to capture the subscriber (aka Subscription)
// so we can clean it up when we close the window
// and open a new one.
closingNotifier.subscribe((closingSubscriber = createOperatorSubscriber(subscriber, openWindow, openWindow, handleError)));
closingNotifier.subscribe((closingSubscriber = createOperatorSubscriber(subscriber, openWindow, noop, handleError)));
};

// Start the first window.
Expand Down