| 1 |
/** |
| 2 |
* Copyright (c) 2018 The xterm.js authors. All rights reserved. |
| 3 |
* @license MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
import { IDisposable, IMarker } from 'common/Types'; |
| 7 |
import { Emitter } from 'vs/base/common/event'; |
| 8 |
import { dispose } from 'vs/base/common/lifecycle'; |
| 9 |
|
| 10 |
export class Marker implements IMarker { |
| 11 |
private static _nextId = 1; |
| 12 |
|
| 13 |
public isDisposed: boolean = false; |
| 14 |
private readonly _disposables: IDisposable[] = []; |
| 15 |
|
| 16 |
private readonly _id: number = Marker._nextId++; |
| 17 |
public get id(): number { return this._id; } |
| 18 |
|
| 19 |
private readonly _onDispose = this.register(new Emitter<void>()); |
| 20 |
public readonly onDispose = this._onDispose.event; |
| 21 |
|
| 22 |
constructor( |
| 23 |
public line: number |
| 24 |
) { |
| 25 |
} |
| 26 |
|
| 27 |
public dispose(): void { |
| 28 |
if (this.isDisposed) { |
| 29 |
return; |
| 30 |
} |
| 31 |
this.isDisposed = true; |
| 32 |
this.line = -1; |
| 33 |
// Emit before super.dispose such that dispose listeners get a change to react |
| 34 |
this._onDispose.fire(); |
| 35 |
dispose(this._disposables); |
| 36 |
this._disposables.length = 0; |
| 37 |
} |
| 38 |
|
| 39 |
public register<T extends IDisposable>(disposable: T): T { |
| 40 |
this._disposables.push(disposable); |
| 41 |
return disposable; |
| 42 |
} |
| 43 |
} |