UNPKG

2.44 kBJavaScriptView Raw
1// Copyright (c) Jupyter Development Team.
2// Distributed under the terms of the Modified BSD License.
3import { Token } from '@lumino/coreutils';
4import { DisposableDelegate } from '@lumino/disposable';
5import { Signal } from '@lumino/signaling';
6/* tslint:disable */
7/**
8 * The application status token.
9 */
10export const ILabStatus = new Token('@jupyterlab/application:ILabStatus');
11/**
12 * The application status signals and flags class.
13 */
14export class LabStatus {
15 /**
16 * Construct a new status object.
17 */
18 constructor(app) {
19 this._busyCount = 0;
20 this._dirtyCount = 0;
21 this._busySignal = new Signal(app);
22 this._dirtySignal = new Signal(app);
23 }
24 /**
25 * Returns a signal for when application changes its busy status.
26 */
27 get busySignal() {
28 return this._busySignal;
29 }
30 /**
31 * Returns a signal for when application changes its dirty status.
32 */
33 get dirtySignal() {
34 return this._dirtySignal;
35 }
36 /**
37 * Whether the application is busy.
38 */
39 get isBusy() {
40 return this._busyCount > 0;
41 }
42 /**
43 * Whether the application is dirty.
44 */
45 get isDirty() {
46 return this._dirtyCount > 0;
47 }
48 /**
49 * Set the application state to dirty.
50 *
51 * @returns A disposable used to clear the dirty state for the caller.
52 */
53 setDirty() {
54 const oldDirty = this.isDirty;
55 this._dirtyCount++;
56 if (this.isDirty !== oldDirty) {
57 this._dirtySignal.emit(this.isDirty);
58 }
59 return new DisposableDelegate(() => {
60 const oldDirty = this.isDirty;
61 this._dirtyCount = Math.max(0, this._dirtyCount - 1);
62 if (this.isDirty !== oldDirty) {
63 this._dirtySignal.emit(this.isDirty);
64 }
65 });
66 }
67 /**
68 * Set the application state to busy.
69 *
70 * @returns A disposable used to clear the busy state for the caller.
71 */
72 setBusy() {
73 const oldBusy = this.isBusy;
74 this._busyCount++;
75 if (this.isBusy !== oldBusy) {
76 this._busySignal.emit(this.isBusy);
77 }
78 return new DisposableDelegate(() => {
79 const oldBusy = this.isBusy;
80 this._busyCount--;
81 if (this.isBusy !== oldBusy) {
82 this._busySignal.emit(this.isBusy);
83 }
84 });
85 }
86}
87//# sourceMappingURL=status.js.map
\No newline at end of file