Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #316 from jtpio/split-files
Browse files Browse the repository at this point in the history
Split breakpoints, variables, sources and callstack into different files
  • Loading branch information
KsavinN committed Dec 23, 2019
2 parents dc9222d + fda96e7 commit 67441e7
Show file tree
Hide file tree
Showing 27 changed files with 1,085 additions and 684 deletions.
20 changes: 10 additions & 10 deletions src/breakpoints/body.tsx
Expand Up @@ -5,19 +5,19 @@ import { ReactWidget } from '@jupyterlab/apputils';

import React, { useEffect, useState } from 'react';

import { Breakpoints } from '.';

import { IDebugger } from '../tokens';

import { BreakpointsModel } from './model';

/**
* The body for a Breakpoints Panel.
*/
export class Body extends ReactWidget {
export class BreakpointsBody extends ReactWidget {
/**
* Instantiate a new Body for the Breakpoints Panel.
* @param model The model for the breakpoints.
*/
constructor(model: Breakpoints.Model) {
constructor(model: BreakpointsModel) {
super();
this._model = model;
this.addClass('jp-DebuggerBreakpoints-body');
Expand All @@ -30,27 +30,27 @@ export class Body extends ReactWidget {
return <BreakpointsComponent model={this._model} />;
}

private _model: Breakpoints.Model;
private _model: BreakpointsModel;
}

/**
* A React component to display a list of breakpoints.
* @param model The model for the breakpoints.
*/
const BreakpointsComponent = ({ model }: { model: Breakpoints.Model }) => {
const BreakpointsComponent = ({ model }: { model: BreakpointsModel }) => {
const [breakpoints, setBreakpoints] = useState(
Array.from(model.breakpoints.entries())
);

useEffect(() => {
const updateBreakpoints = (
_: Breakpoints.Model,
_: BreakpointsModel,
updates: IDebugger.IBreakpoint[]
) => {
setBreakpoints(Array.from(model.breakpoints.entries()));
};

const restoreBreakpoints = (_: Breakpoints.Model) => {
const restoreBreakpoints = (_: BreakpointsModel) => {
setBreakpoints(Array.from(model.breakpoints.entries()));
};

Expand Down Expand Up @@ -86,7 +86,7 @@ const BreakpointCellComponent = ({
model
}: {
breakpoints: IDebugger.IBreakpoint[];
model: Breakpoints.Model;
model: BreakpointsModel;
}) => {
return (
<>
Expand Down Expand Up @@ -115,7 +115,7 @@ const BreakpointComponent = ({
model
}: {
breakpoint: IDebugger.IBreakpoint;
model: Breakpoints.Model;
model: BreakpointsModel;
}) => {
return (
<div
Expand Down
31 changes: 31 additions & 0 deletions src/breakpoints/header.ts
@@ -0,0 +1,31 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { Toolbar } from '@jupyterlab/apputils';

import { PanelLayout, Widget } from '@phosphor/widgets';

/**
* The header for a Breakpoints Panel.
*/
export class BreakpointsHeader extends Widget {
/**
* Instantiate a new BreakpointsHeader.
*/
constructor() {
super({ node: document.createElement('header') });

const title = new Widget({ node: document.createElement('h2') });
title.node.textContent = 'Breakpoints';

const layout = new PanelLayout();
layout.addWidget(title);
layout.addWidget(this.toolbar);
this.layout = layout;
}

/**
* The toolbar for the breakpoints header.
*/
readonly toolbar = new Toolbar();
}
127 changes: 9 additions & 118 deletions src/breakpoints/index.ts
@@ -1,17 +1,17 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { Toolbar, ToolbarButton } from '@jupyterlab/apputils';
import { ToolbarButton } from '@jupyterlab/apputils';

import { IDisposable } from '@phosphor/disposable';
import { Panel } from '@phosphor/widgets';

import { ISignal, Signal } from '@phosphor/signaling';
import { IDebugger } from '../tokens';

import { Panel, PanelLayout, Widget } from '@phosphor/widgets';
import { BreakpointsBody } from './body';

import { IDebugger } from '../tokens';
import { BreakpointsHeader } from './header';

import { Body } from './body';
import { BreakpointsModel } from './model';

/**
* A Panel to show a list of breakpoints.
Expand All @@ -26,7 +26,7 @@ export class Breakpoints extends Panel {
const { model, service } = options;

const header = new BreakpointsHeader();
const body = new Body(model);
const body = new BreakpointsBody(model);

header.toolbar.addItem(
'closeAll',
Expand All @@ -46,127 +46,18 @@ export class Breakpoints extends Panel {
}
}

/**
* The header for a Breakpoints Panel.
*/
class BreakpointsHeader extends Widget {
/**
* Instantiate a new BreakpointsHeader.
*/
constructor() {
super({ node: document.createElement('header') });

const title = new Widget({ node: document.createElement('h2') });
title.node.textContent = 'Breakpoints';

const layout = new PanelLayout();
layout.addWidget(title);
layout.addWidget(this.toolbar);
this.layout = layout;
}

/**
* The toolbar for the breakpoints header.
*/
readonly toolbar = new Toolbar();
}

/**
* A namespace for Breakpoints `statics`.
*/
export namespace Breakpoints {
/**
* A model for a list of breakpoints.
*/
export class Model 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);
}

/**
* Instantiation options for `Breakpoints`.
*/
export interface IOptions extends Panel.IOptions {
/**
* The debugger model.
* The breakpoints model.
*/
model: Model;
model: BreakpointsModel;

/**
* The debugger service.
Expand Down
92 changes: 92 additions & 0 deletions src/breakpoints/model.ts
@@ -0,0 +1,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);
}

0 comments on commit 67441e7

Please sign in to comment.