Skip to content

Commit

Permalink
fix(bufferToggle): don't signal on complete
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Oct 27, 2020
1 parent c5df6f7 commit 0f7ed01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
12 changes: 5 additions & 7 deletions spec/operators/bufferToggle-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('bufferToggle operator', () => {
});
});

it('should emit buffers using varying empty delayed closings', () => {
it('should not emit closed buffers using varying empty delayed closings', () => {
testScheduler.run(({ hot, cold, expectObservable, expectSubscriptions }) => {
const e1 = hot('--a--^---b---c---d---e---f---g---h------| ');
const e2 = cold(' --x-----------y--------z---| ');
Expand All @@ -137,11 +137,9 @@ describe('bufferToggle operator', () => {
cold(' ----| '),
cold(' ---------------| ')
];
const expected = ' -----------------ij----------------(k|)';
const expected = ' -----------------------------------(i|)';
const values = {
i: ['b', 'c', 'd', 'e'],
j: ['e'],
k: ['g', 'h']
i: ['g', 'h']
};

let i = 0;
Expand Down Expand Up @@ -503,11 +501,11 @@ describe('bufferToggle operator', () => {
const e1 = hot('--a--^---b---c---d---e---f---g---h------|');
const subs = ' ^----------------------------------!';
const e2 = cold(' --x-----------y--------z---| ');
const expected = ' --l-----------m--------n-----------|';
const expected = ' -----------------------------------|';

const result = e1.pipe(bufferToggle(e2, () => EMPTY));

expectObservable(result).toBe(expected, {l: [], m: [], n: []});
expectObservable(result).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(subs);
});
});
Expand Down
11 changes: 6 additions & 5 deletions src/internal/operators/bufferToggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,19 @@ export function bufferToggle<T, O>(
// when the closing notifier emits, we can tear it down.
const closingSubscription = new Subscription();

// This is captured here, because we emit on both next or
// if the closing notifier completes without value.
// TODO: We probably want to not have closing notifiers emit!!
const emit = () => {
const emitBuffer = () => {
arrRemove(buffers, buffer);
subscriber.next(buffer);
closingSubscription.unsubscribe();
};

const discardBuffer = () => {
arrRemove(buffers, buffer);
};

// The line below will add the subscription to the parent subscriber *and* the closing subscription.
closingSubscription.add(
innerFrom(closingSelector(openValue)).subscribe(new OperatorSubscriber(subscriber, emit, undefined, emit))
innerFrom(closingSelector(openValue)).subscribe(new OperatorSubscriber(subscriber, emitBuffer, undefined, discardBuffer))
);
},
undefined,
Expand Down

0 comments on commit 0f7ed01

Please sign in to comment.