Skip to content

Commit

Permalink
working on typescript interface
Browse files Browse the repository at this point in the history
  • Loading branch information
gwincr11 committed Nov 30, 2022
1 parent d1482b6 commit 8f19587
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
46 changes: 21 additions & 25 deletions packages/nbdime/src/diff/widget/linked-cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,42 @@ export const foldIcon = new LabIcon({
});

export interface ILinkedListCell {
next: () => ILinkedListCell | null;
prev: () => ILinkedListCell | null;
displayed: () => boolean;
_next: ILinkedListCell | null;
_prev: ILinkedListCell | null;
displayed: boolean;
lazy: boolean;
expandUp: () => void;
expandDown: () => void;
}

class LinkedListCell extends Panel {
_next: LinkedListCell | LazyDisplayLinkedListCell | null;
_prev: LinkedListCell | LazyDisplayLinkedListCell | null;
class LinkedListCell extends Panel implements ILinkedListCell {
renderFunc: () => CellDiffWidget;
_displayed: boolean;
displayed: boolean;
_next: ILinkedListCell | null;
_prev: ILinkedListCell | null;
lazy: boolean;

constructor(renderFunc: () => CellDiffWidget) {
super();
this._next = null;
this._prev = null;
this.renderFunc = renderFunc;
this._displayed = true;
this.displayed = true;
this.renderCell();
this.addClass("linked-cell");
this.lazy = false;
}

protected renderCell() {
this.addWidget(this.renderFunc());
this._displayed = true;
this.displayed = true;
}

get next(): LinkedListCell | LazyDisplayLinkedListCell | null {
get next() {
return this._next;
}

set next(nextCell: LinkedListCell | LazyDisplayLinkedListCell | null) {
set next(nextCell) {
this._next = nextCell;
if (nextCell === null) {
return;
Expand All @@ -68,25 +68,21 @@ class LinkedListCell extends Panel {
}
}

get prev(): LinkedListCell | LazyDisplayLinkedListCell | null {
get prev() {
return this._prev;
}

set prev(prevCell: LinkedListCell | LazyDisplayLinkedListCell | null) {
set prev(prevCell) {
this._prev = prevCell;
if (prevCell === null) {
return;
}
prevCell.next = this;
prevCell._next = this as ILinkedListCell;
if (prevCell.lazy) {
prevCell.expandUp();
}
}

get displayed(): boolean {
return this._displayed;
}

expandUp(): void {
return;
}
Expand Down Expand Up @@ -120,11 +116,11 @@ class LazyDisplayLinkedListCell extends LinkedListCell {
}

protected renderCell() {
this._displayed = false;
this.displayed = false;
}

expandUp(): void {
if (this._displayed) {
if (this.displayed) {
return;
}
if (this.expandButtonDisplayed) {
Expand All @@ -135,7 +131,7 @@ class LazyDisplayLinkedListCell extends LinkedListCell {
}

expandDown(): void {
if (this._displayed) {
if (this.displayed) {
return;
}
if (this.expandButtonDisplayed) {
Expand Down Expand Up @@ -194,11 +190,11 @@ class LazyDisplayLinkedListCell extends LinkedListCell {

buttonSvg(direction: "Up" | "Down" | "Fold"): LabIcon {
if (direction === "Up") {
return foldUp;
return foldUpIcon;
} else if (direction === "Down") {
return foldDown;
return foldDownIcon;
} else {
return fold;
return foldIcon;
}
}

Expand All @@ -214,7 +210,7 @@ class LazyDisplayLinkedListCell extends LinkedListCell {

showLazyCell() {
this.addWidget(this.renderFunc());
this._displayed = true;
this.displayed = true;
this.expandButton.remove();
}
}
Expand Down
11 changes: 7 additions & 4 deletions packages/nbdime/src/diff/widget/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ import { NotebookDiffModel, CellDiffModel } from "../model";

const NBDIFF_CLASS = "jp-Notebook-diff";

type Command<T> = new (renderFunc: ()=> CellDiffWidget) => T


/**
* NotebookDiffWidget
*/
export class NotebookDiffWidget extends Panel {
constructor(
model: NotebookDiffModel,
rendermime: IRenderMimeRegistry,
displayedCellWrapper: ILinkedListCell = LinkedListCell,
lazyDisplayWrapper: ILinkedListCell = LazyDisplayLinkedListCell
displayedCellWrapper: Command<ILinkedListCell> = LinkedListCell,
lazyDisplayWrapper: Command<LazyDisplayLinkedListCell> = LazyDisplayLinkedListCell
) {
super();
this._model = model;
Expand Down Expand Up @@ -143,6 +146,6 @@ export class NotebookDiffWidget extends Panel {
private _model: NotebookDiffModel;
private _rendermime: IRenderMimeRegistry;
private previousCell: LinkedListCell | null;
private displayedCellWrapper: LinkedListCell;
private lazyDisplayWrapper: LazyDisplayLinkedListCell;
private displayedCellWrapper: Command<ILinkedListCell>;
private lazyDisplayWrapper: Command<ILinkedListCell>;
}

0 comments on commit 8f19587

Please sign in to comment.