This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
model.ts
92 lines (79 loc) · 2.18 KB
/
model.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { IDisposable } from '@phosphor/disposable';
import { ISignal, Signal } from '@phosphor/signaling';
import { IDebugger } from '../tokens';
/**
* A model for a list of breakpoints.
*/
export class BreakpointsModel implements IDisposable {
/**
* Whether the model is disposed.
*/
get isDisposed(): boolean {
return this._isDisposed;
}
/**
* Signal emitted when the model changes.
*/
get changed(): ISignal<this, IDebugger.IBreakpoint[]> {
return this._changed;
}
/**
* Signal emitted when the breakpoints are restored.
*/
get restored(): Signal<this, void> {
return this._restored;
}
/**
* Signal emitted when a breakpoint is clicked.
*/
get clicked(): Signal<this, IDebugger.IBreakpoint> {
return this._clicked;
}
/**
* Get all the breakpoints.
*/
get breakpoints(): Map<string, IDebugger.IBreakpoint[]> {
return this._breakpoints;
}
/**
* Dispose the model.
*/
dispose(): void {
if (this._isDisposed) {
return;
}
this._isDisposed = true;
Signal.clearData(this);
}
/**
* Set the breakpoints for a given id (path).
* @param id The code id (path).
* @param breakpoints The list of breakpoints.
*/
setBreakpoints(id: string, breakpoints: IDebugger.IBreakpoint[]) {
this._breakpoints.set(id, breakpoints);
this._changed.emit(breakpoints);
}
/**
* Get the breakpoints for a given id (path).
* @param id The code id (path).
*/
getBreakpoints(id: string): IDebugger.IBreakpoint[] {
return this._breakpoints.get(id) ?? [];
}
/**
* Restore a map of breakpoints.
* @param breakpoints The map of breakpoints
*/
restoreBreakpoints(breakpoints: Map<string, IDebugger.IBreakpoint[]>) {
this._breakpoints = breakpoints;
this._restored.emit();
}
private _isDisposed = false;
private _breakpoints = new Map<string, IDebugger.IBreakpoint[]>();
private _changed = new Signal<this, IDebugger.IBreakpoint[]>(this);
private _restored = new Signal<this, void>(this);
private _clicked = new Signal<this, IDebugger.IBreakpoint>(this);
}