Skip to content

Commit 8f2b16d

Browse files
committed
Remove template from DiffModel
1 parent 41cc8ee commit 8f2b16d

File tree

8 files changed

+43
-48
lines changed

8 files changed

+43
-48
lines changed

src/commandsAndMenu.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ export function addCommands(
419419
/**
420420
* Git display diff command - internal command
421421
*
422-
* @params model {Git.Diff.IModel<string>}: The diff model to display
422+
* @params model {Git.Diff.IModel: The diff model to display
423423
* @params isText {boolean}: Optional, whether the content is a plain text
424424
* @params isMerge {boolean}: Optional, whether the diff is a merge conflict
425425
* @returns the main area widget or null
@@ -429,7 +429,7 @@ export function addCommands(
429429
caption: trans.__('Display a file diff.'),
430430
execute: async args => {
431431
const { model, isText } = args as any as {
432-
model: Git.Diff.IModel<string>;
432+
model: Git.Diff.IModel;
433433
isText?: boolean;
434434
};
435435

@@ -633,10 +633,7 @@ export function addCommands(
633633
: { git: diffContext.currentRef };
634634

635635
// Base props used for Diff Model
636-
const props: Omit<
637-
Git.Diff.IModel<string>,
638-
'changed' | 'hasConflict'
639-
> = {
636+
const props: Omit<Git.Diff.IModel, 'changed' | 'hasConflict'> = {
640637
challenger: {
641638
content: async () => {
642639
return requestAPI<Git.IDiffContent>(
@@ -697,7 +694,7 @@ export function addCommands(
697694
}
698695

699696
// Create the diff widget
700-
const model = new DiffModel<string>(props);
697+
const model = new DiffModel(props);
701698

702699
const widget = await commands.execute(CommandIDs.gitShowDiff, {
703700
model,

src/components/diff/NotebookDiff.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ interface INbdimeMergeDiff {
7575
* @returns Diff notebook widget
7676
*/
7777
export const createNotebookDiff = async (
78-
model: Git.Diff.IModel<string>,
78+
model: Git.Diff.IModel,
7979
renderMime: IRenderMimeRegistry,
8080
toolbar?: Toolbar
8181
): Promise<NotebookDiff> => {
@@ -116,7 +116,7 @@ export const createNotebookDiff = async (
116116
* NotebookDiff widget
117117
*/
118118
export class NotebookDiff extends Panel implements Git.Diff.IDiffWidget {
119-
constructor(model: Git.Diff.IModel<string>, renderMime: IRenderMimeRegistry) {
119+
constructor(model: Git.Diff.IModel, renderMime: IRenderMimeRegistry) {
120120
super();
121121
const getReady = new PromiseDelegate<void>();
122122
this._isReady = getReady.promise;
@@ -335,7 +335,7 @@ export class NotebookDiff extends Panel implements Git.Diff.IDiffWidget {
335335

336336
protected _areUnchangedCellsHidden = false;
337337
protected _isReady: Promise<void>;
338-
protected _model: Git.Diff.IModel<string>;
338+
protected _model: Git.Diff.IModel;
339339
protected _renderMime: IRenderMimeRegistry;
340340
protected _scroller: Panel;
341341
protected _nbdWidget: NotebookMergeWidget | NotebookDiffWidget;

src/components/diff/PlainTextDiff.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import { MergeView as LocalMergeView, mergeView } from './mergeview';
1414
* @param toolbar MainAreaWidget toolbar
1515
* @returns PlainText diff widget
1616
*/
17-
export const createPlainTextDiff: Git.Diff.ICallback<string> = async (
18-
model: Git.Diff.IModel<string>,
17+
export const createPlainTextDiff: Git.Diff.ICallback = async (
18+
model: Git.Diff.IModel,
1919
toolbar?: Toolbar
2020
): Promise<PlainTextDiff> => {
2121
const widget = new PlainTextDiff(model);
@@ -27,7 +27,7 @@ export const createPlainTextDiff: Git.Diff.ICallback<string> = async (
2727
* Plain Text Diff widget
2828
*/
2929
export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
30-
constructor(model: Git.Diff.IModel<string>) {
30+
constructor(model: Git.Diff.IModel) {
3131
super({
3232
node: PlainTextDiff.createNode(
3333
model.reference.label,
@@ -256,7 +256,7 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
256256
protected _container: HTMLElement;
257257
protected _isReady: Promise<void>;
258258
protected _mergeView: MergeView.MergeViewEditor;
259-
protected _model: Git.Diff.IModel<string>;
259+
protected _model: Git.Diff.IModel;
260260

261261
private _reference: string | null = null;
262262
private _challenger: string | null = null;

src/components/diff/model.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import { Git } from '../../tokens';
55
/**
66
* Base DiffModel class
77
*/
8-
export class DiffModel<T> implements IDisposable, Git.Diff.IModel<T> {
9-
constructor(props: Omit<Git.Diff.IModel<T>, 'changed' | 'hasConflict'>) {
8+
export class DiffModel implements IDisposable, Git.Diff.IModel {
9+
constructor(props: Omit<Git.Diff.IModel, 'changed' | 'hasConflict'>) {
1010
this._challenger = props.challenger;
1111
this._filename = props.filename;
1212
this._reference = props.reference;
1313
this._base = props.base;
1414

15-
this._changed = new Signal<DiffModel<T>, Git.Diff.IModelChange>(this);
15+
this._changed = new Signal<DiffModel, Git.Diff.IModelChange>(this);
1616
}
1717

1818
/**
@@ -22,16 +22,16 @@ export class DiffModel<T> implements IDisposable, Git.Diff.IModel<T> {
2222
* on challenger change except for the content; i.e. the content
2323
* is not fetch to check if it changed.
2424
*/
25-
get changed(): ISignal<DiffModel<T>, Git.Diff.IModelChange> {
25+
get changed(): ISignal<DiffModel, Git.Diff.IModelChange> {
2626
return this._changed;
2727
}
2828

2929
/**
3030
* Helper to compare diff contents.
3131
*/
3232
private _didContentChange(
33-
a: Git.Diff.IContent<T>,
34-
b: Git.Diff.IContent<T>
33+
a: Git.Diff.IContent,
34+
b: Git.Diff.IContent
3535
): boolean {
3636
return (
3737
a.label !== b.label || a.source !== b.source || a.updateAt !== b.updateAt
@@ -41,10 +41,10 @@ export class DiffModel<T> implements IDisposable, Git.Diff.IModel<T> {
4141
/**
4242
* Challenger description
4343
*/
44-
get challenger(): Git.Diff.IContent<T> {
44+
get challenger(): Git.Diff.IContent {
4545
return this._challenger;
4646
}
47-
set challenger(v: Git.Diff.IContent<T>) {
47+
set challenger(v: Git.Diff.IContent) {
4848
const emitSignal = this._didContentChange(this._challenger, v);
4949

5050
if (emitSignal) {
@@ -63,10 +63,10 @@ export class DiffModel<T> implements IDisposable, Git.Diff.IModel<T> {
6363
/**
6464
* Reference description
6565
*/
66-
get reference(): Git.Diff.IContent<T> {
66+
get reference(): Git.Diff.IContent {
6767
return this._reference;
6868
}
69-
set reference(v: Git.Diff.IContent<T>) {
69+
set reference(v: Git.Diff.IContent) {
7070
const emitSignal = this._didContentChange(this._reference, v);
7171

7272
if (emitSignal) {
@@ -81,7 +81,7 @@ export class DiffModel<T> implements IDisposable, Git.Diff.IModel<T> {
8181
* Note: The base diff content is only provided during
8282
* merge conflicts (three-way diff).
8383
*/
84-
get base(): Git.Diff.IContent<T> | undefined {
84+
get base(): Git.Diff.IContent | undefined {
8585
return this._base;
8686
}
8787

@@ -110,11 +110,11 @@ export class DiffModel<T> implements IDisposable, Git.Diff.IModel<T> {
110110
Signal.clearData(this);
111111
}
112112

113-
protected _reference: Git.Diff.IContent<T>;
114-
protected _challenger: Git.Diff.IContent<T>;
115-
protected _base?: Git.Diff.IContent<T>;
113+
protected _reference: Git.Diff.IContent;
114+
protected _challenger: Git.Diff.IContent;
115+
protected _base?: Git.Diff.IContent;
116116

117-
private _changed: Signal<DiffModel<T>, Git.Diff.IModelChange>;
117+
private _changed: Signal<DiffModel, Git.Diff.IModelChange>;
118118
private _isDisposed = false;
119119
private _filename: string;
120120
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ async function activate(
209209
gitExtension.registerDiffProvider(
210210
'Nbdime',
211211
['.ipynb'],
212-
(model: Git.Diff.IModel<string>, toolbar?: Toolbar) =>
212+
(model: Git.Diff.IModel, toolbar?: Toolbar) =>
213213
createNotebookDiff(model, renderMime, toolbar)
214214
);
215215

src/model.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { decodeStage } from './utils';
1414
const DEFAULT_REFRESH_INTERVAL = 3000; // ms
1515
// Available diff providers
1616
const DIFF_PROVIDERS: {
17-
[key: string]: { name: string; callback: Git.Diff.ICallback<any> };
17+
[key: string]: { name: string; callback: Git.Diff.ICallback };
1818
} = {};
1919

2020
/**
@@ -24,7 +24,7 @@ const DIFF_PROVIDERS: {
2424
*/
2525
export function getDiffProvider(
2626
filename: string
27-
): Git.Diff.ICallback<any> | undefined {
27+
): Git.Diff.ICallback | undefined {
2828
return DIFF_PROVIDERS[PathExt.extname(filename)?.toLocaleLowerCase()]
2929
?.callback;
3030
}
@@ -1129,10 +1129,10 @@ export class GitExtension implements IGitExtension {
11291129
* @param fileExtensions File type list
11301130
* @param callback Callback to use for the provided file types
11311131
*/
1132-
registerDiffProvider<T>(
1132+
registerDiffProvider(
11331133
name: string,
11341134
fileExtensions: string[],
1135-
callback: Git.Diff.ICallback<T>
1135+
callback: Git.Diff.ICallback
11361136
): void {
11371137
fileExtensions.forEach(fileExtension => {
11381138
DIFF_PROVIDERS[fileExtension.toLocaleLowerCase()] = { name, callback };

src/tokens.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,10 @@ export interface IGitExtension extends IDisposable {
372372
* @param fileExtensions File extensions list
373373
* @param callback Callback to use for the provided file types
374374
*/
375-
registerDiffProvider<T>(
375+
registerDiffProvider(
376376
name: string,
377377
fileExtensions: string[],
378-
callback: Git.Diff.ICallback<T>
378+
callback: Git.Diff.ICallback
379379
): void;
380380

381381
/**
@@ -490,24 +490,22 @@ export namespace Git {
490490
/**
491491
* Callback to generate a comparison widget
492492
*
493-
* T is the content type to be compared
494-
*
495493
* The toolbar is the one of the MainAreaWidget in which the diff widget
496494
* will be displayed.
497495
*/
498-
export type ICallback<T> = (
499-
model: IModel<T>,
496+
export type ICallback = (
497+
model: IModel,
500498
toolbar?: Toolbar
501499
) => Promise<IDiffWidget>;
502500

503501
/**
504502
* Content and its context for diff
505503
*/
506-
export interface IContent<T> {
504+
export interface IContent {
507505
/**
508506
* Asynchronous content getter for the source
509507
*/
510-
content: () => Promise<T>;
508+
content: () => Promise<string>;
511509
/**
512510
* Content label
513511
*
@@ -550,27 +548,27 @@ export namespace Git {
550548
/**
551549
* DiffModel properties
552550
*/
553-
export interface IModel<T> {
551+
export interface IModel {
554552
/**
555553
* Challenger data
556554
*/
557-
challenger: IContent<T>;
555+
challenger: IContent;
558556
/**
559557
* Signal emitted when the reference or the challenger changes
560558
*/
561-
readonly changed: ISignal<IModel<T>, IModelChange>;
559+
readonly changed: ISignal<IModel, IModelChange>;
562560
/**
563561
* File of the name being diff at reference state
564562
*/
565563
readonly filename: string;
566564
/**
567565
* Reference data
568566
*/
569-
reference: IContent<T>;
567+
reference: IContent;
570568
/**
571569
* Optional base data, used only during merge conflicts
572570
*/
573-
base?: IContent<T>;
571+
base?: IContent;
574572
/**
575573
* Helper to check if the file has conflicts.
576574
*/

tests/test-components/DiffModel.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { DiffModel } from '../../src/components/diff/model';
44
import { Git } from '../../src/tokens';
55

66
describe('DiffModel', () => {
7-
let model: DiffModel<string>;
7+
let model: DiffModel;
88

99
/**
1010
* Helper to test changed signal.

0 commit comments

Comments
 (0)