Skip to content

Commit

Permalink
fix(sample): don't signal on complete
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the sample operator's notifier observable must emit a next notification to effect a sample. Complete notifications no longer effect a sample.
  • Loading branch information
cartant authored and benlesh committed Nov 3, 2020
1 parent 54cb428 commit 95e0b70
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions spec/operators/sample-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ describe('sample operator', () => {
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});

it('should sample when the notifier completes', () => {
it('should not sample when the notifier completes', () => {
const e1 = hot('----a-^------b----------|');
const e1subs = '^ !';
const e2 = hot( '-----x-----|');
const e2subs = '^ !';
const expected = '-----------b------|';
const expected = '------------------|';

expectObservable(e1.pipe(sample(e2))).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand Down
8 changes: 4 additions & 4 deletions src/internal/operators/sample.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @prettier */
import { Observable } from '../Observable';

import { MonoTypeOperatorFunction } from '../types';
import { operate } from '../util/lift';
import { noop } from '../util/noop';
import { OperatorSubscriber } from './OperatorSubscriber';

/**
Expand All @@ -14,7 +14,7 @@ import { OperatorSubscriber } from './OperatorSubscriber';
*
* ![](sample.png)
*
* Whenever the `notifier` Observable emits a value or completes, `sample`
* Whenever the `notifier` Observable emits a value, `sample`
* looks at the source Observable and emits whichever value it has most recently
* emitted since the previous sampling, unless the source has not emitted
* anything since the previous sampling. The `notifier` is subscribed to as soon
Expand All @@ -41,7 +41,7 @@ import { OperatorSubscriber } from './OperatorSubscriber';
* source Observable.
* @return {Observable<T>} An Observable that emits the results of sampling the
* values emitted by the source Observable whenever the notifier Observable
* emits value or completes.
* emits value.
*/
export function sample<T>(notifier: Observable<any>): MonoTypeOperatorFunction<T> {
return operate((source, subscriber) => {
Expand All @@ -61,6 +61,6 @@ export function sample<T>(notifier: Observable<any>): MonoTypeOperatorFunction<T
subscriber.next(value);
}
};
notifier.subscribe(new OperatorSubscriber(subscriber, emit, undefined, emit));
notifier.subscribe(new OperatorSubscriber(subscriber, emit, undefined, noop));
});
}

0 comments on commit 95e0b70

Please sign in to comment.