|
1 | 1 | /*--------------------------------------------------------------------------------------------- |
2 | 2 | * Copyright (c) Microsoft Corporation. All rights reserved. |
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | | - *--------------------------------------------------------------------------------------------*/ |
5 | | - |
6 | | -import { Subscription } from "rxjs/Subscription"; |
7 | | -import Disposable, { IDisposable } from "./Disposable"; |
8 | | - |
9 | | -export default class CompositeDisposable extends Disposable { |
10 | | - private disposables = new Subscription(); |
11 | | - |
12 | | - constructor (...disposables: IDisposable[]){ |
13 | | - super(() => this.disposables.unsubscribe()); |
14 | | - |
15 | | - for (const disposable of disposables) { |
16 | | - if (disposable) { |
17 | | - this.disposables.add(disposable.dispose); |
18 | | - } |
19 | | - else { |
20 | | - throw new Error("null disposables are not supported"); |
21 | | - } |
22 | | - } |
23 | | - } |
24 | | - |
25 | | - public add(disposable: IDisposable) { |
26 | | - if (!disposable) { |
27 | | - throw new Error("disposable cannot be null"); |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import { Subscription } from "rxjs/Subscription"; |
| 7 | +import Disposable, { IDisposable } from "./Disposable"; |
| 8 | + |
| 9 | +export default class CompositeDisposable extends Disposable { |
| 10 | + private disposables = new Subscription(); |
| 11 | + |
| 12 | + constructor(...disposables: IDisposable[]) { |
| 13 | + super(() => this.disposables.unsubscribe()); |
| 14 | + |
| 15 | + for (const disposable of disposables) { |
| 16 | + if (disposable) { |
| 17 | + this.disposables.add(() => disposable.dispose()); |
| 18 | + } |
| 19 | + else { |
| 20 | + throw new Error("null disposables are not supported"); |
| 21 | + } |
28 | 22 | } |
29 | | - |
30 | | - this.disposables.add(disposable.dispose); |
31 | | - } |
| 23 | + } |
| 24 | + |
| 25 | + public add(disposable: IDisposable) { |
| 26 | + if (!disposable) { |
| 27 | + throw new Error("disposable cannot be null"); |
| 28 | + } |
| 29 | + |
| 30 | + this.disposables.add(() => disposable.dispose()); |
| 31 | + } |
32 | 32 | } |
0 commit comments