Skip to content

Commit

Permalink
feat(rxjs-core): add SubscriptionManager.manage()
Browse files Browse the repository at this point in the history
  • Loading branch information
ersimont committed Feb 3, 2021
1 parent 317972c commit 4b1aad6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions projects/rxjs-core/src/lib/subscription-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ describe('SubscriptionManager', () => {
});
});

describe('.manage()', () => {
it('causes the manager to manage the passed-in subscription', () => {
const subject = new Subject();
manager.manage(subject.subscribe(next));

manager.unsubscribe();
subject.next();
expect(next).not.toHaveBeenCalled();
});
});

describe('.unsubscribe()', () => {
it('stop callbacks', () => {
const subject1 = new Subject();
Expand Down
5 changes: 5 additions & 0 deletions projects/rxjs-core/src/lib/subscription-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Observable, Subscription, Unsubscribable } from 'rxjs';
* }
* ```
*/
/* eslint-disable max-lines-per-function */
// tslint:disable-next-line:typedef
export function mixInSubscriptionManager<B extends Constructor>(Base: B) {
return class extends Base implements Unsubscribable {
Expand All @@ -32,6 +33,10 @@ export function mixInSubscriptionManager<B extends Constructor>(Base: B) {
);
}

manage(subscription: Subscription): void {
this.#subscriptions.add(subscription);
}

unsubscribe(): void {
this.#subscriptions.unsubscribe();
this.#subscriptions = new Subscription();
Expand Down

0 comments on commit 4b1aad6

Please sign in to comment.