Skip to content

Commit 097c74f

Browse files
committed
Consolidates view node splatting
1 parent ba5dfbb commit 097c74f

23 files changed

+49
-73
lines changed

src/views/branchesView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class BranchesViewNode extends RepositoriesSubscribeableNode<BranchesView
7676

7777
const splat = repositories.length === 1;
7878
this.children = repositories.map(
79-
r => new BranchesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat),
79+
r => new BranchesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r),
8080
);
8181
}
8282

src/views/commitsView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class CommitsViewNode extends RepositoriesSubscribeableNode<CommitsView,
136136
const splat = repositories.length === 1;
137137
this.children = repositories.map(
138138
r =>
139-
new CommitsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat, {
139+
new CommitsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r, {
140140
showBranchAndLastFetched: true,
141141
}),
142142
);

src/views/contributorsView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class ContributorsViewNode extends RepositoriesSubscribeableNode<Contribu
7676

7777
const splat = repositories.length === 1;
7878
this.children = repositories.map(
79-
r => new ContributorsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat),
79+
r => new ContributorsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r),
8080
);
8181
}
8282

src/views/nodes/abstract/repositoriesSubscribeableNode.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ export abstract class RepositoriesSubscribeableNode<
1313
TView extends View = View,
1414
TChild extends ViewNode = ViewNode,
1515
> extends SubscribeableViewNode<'repositories', TView, TChild> {
16-
protected override splatted = true;
17-
1816
constructor(view: TView) {
19-
super('repositories', unknownGitUri, view);
17+
super('repositories', unknownGitUri, view, undefined, true);
2018
}
2119

2220
override async getSplattedChild() {

src/views/nodes/abstract/repositoryFolderNode.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,18 @@ export abstract class RepositoryFolderNode<
1919
TView extends View = View,
2020
TChild extends ViewNode = ViewNode,
2121
> extends SubscribeableViewNode<'repo-folder', TView> {
22-
protected override splatted = true;
23-
2422
constructor(
2523
uri: GitUri,
2624
view: TView,
2725
protected override readonly parent: ViewNode,
28-
public readonly repo: Repository,
2926
splatted: boolean,
27+
public readonly repo: Repository,
3028
private readonly options?: { showBranchAndLastFetched?: boolean },
3129
) {
32-
super('repo-folder', uri, view, parent);
30+
super('repo-folder', uri, view, parent, splatted);
3331

3432
this.updateContext({ repository: this.repo });
3533
this._uniqueId = getViewNodeId(this.type, this.context);
36-
37-
this.splatted = splatted;
3834
}
3935

4036
private _child: TChild | undefined;
@@ -66,8 +62,6 @@ export abstract class RepositoryFolderNode<
6662
}
6763

6864
async getTreeItem(): Promise<TreeItem> {
69-
this.splatted = false;
70-
7165
const branch = await this.repo.git.getBranch();
7266
const ahead = (branch?.state.ahead ?? 0) > 0;
7367
const behind = (branch?.state.behind ?? 0) > 0;

src/views/nodes/abstract/subscribeableViewNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export abstract class SubscribeableViewNode<
2121

2222
protected loaded: boolean = false;
2323

24-
constructor(type: Type, uri: GitUri, view: TView, parent?: ViewNode) {
25-
super(type, uri, view, parent);
24+
constructor(type: Type, uri: GitUri, view: TView, parent?: ViewNode, splatted?: boolean) {
25+
super(type, uri, view, parent, splatted);
2626

2727
const disposables = [
2828
weakEvent(this.view.onDidChangeVisibility, this.onVisibilityChanged, this),

src/views/nodes/abstract/viewNode.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export abstract class ViewNode<
253253
}
254254

255255
protected _uniqueId!: string;
256-
protected splatted = false;
256+
splatted = false;
257257
// NOTE: @eamodio uncomment to track node leaks
258258
// readonly uuid = uuid();
259259

@@ -262,8 +262,12 @@ export abstract class ViewNode<
262262
// public readonly id: string | undefined,
263263
uri: GitUri,
264264
public readonly view: TView,
265-
protected parent?: ViewNode,
265+
protected parent?: ViewNode | undefined,
266+
//** Indicates if this node is only shown as its children, not itself */
267+
splatted?: boolean,
266268
) {
269+
this.splatted = splatted ?? false;
270+
267271
// NOTE: @eamodio uncomment to track node leaks
268272
// queueMicrotask(() => this.view.registerNode(this));
269273
this._uri = uri;
@@ -339,32 +343,36 @@ export abstract class ViewNode<
339343

340344
getSplattedChild?(): Promise<ViewNode | undefined>;
341345

346+
protected get storedId(): string | undefined {
347+
return this.id;
348+
}
349+
342350
deleteState<T extends StateKey<State> = StateKey<State>>(key?: T): void {
343-
if (this.id == null) {
351+
if (this.storedId == null) {
344352
debugger;
345353
throw new Error('Id is required to delete state');
346354
}
347-
this.view.nodeState.deleteState(this.id, key as string);
355+
this.view.nodeState.deleteState(this.storedId, key as string);
348356
}
349357

350358
getState<T extends StateKey<State> = StateKey<State>>(key: T): StateValue<State, T> | undefined {
351-
if (this.id == null) {
359+
if (this.storedId == null) {
352360
debugger;
353361
throw new Error('Id is required to get state');
354362
}
355-
return this.view.nodeState.getState(this.id, key as string);
363+
return this.view.nodeState.getState(this.storedId, key as string);
356364
}
357365

358366
storeState<T extends StateKey<State> = StateKey<State>>(
359367
key: T,
360368
value: StateValue<State, T>,
361369
sticky?: boolean,
362370
): void {
363-
if (this.id == null) {
371+
if (this.storedId == null) {
364372
debugger;
365373
throw new Error('Id is required to store state');
366374
}
367-
this.view.nodeState.storeState(this.id, key as string, value, sticky);
375+
this.view.nodeState.storeState(this.storedId, key as string, value, sticky);
368376
}
369377
}
370378

src/views/nodes/abstract/viewRefNode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ export abstract class ViewRefNode<
1717
uri: GitUri,
1818
view: TView,
1919
protected override readonly parent: ViewNode,
20+
splatted?: boolean,
2021
) {
21-
super(type, uri, view, parent);
22+
super(type, uri, view, parent, splatted);
2223
}
2324

2425
abstract get ref(): TReference;

src/views/nodes/branchNode.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export class BranchNode
6969
limit: number | undefined;
7070

7171
private readonly options: Options;
72-
protected override splatted = true;
7372

7473
constructor(
7574
uri: GitUri,
@@ -81,7 +80,7 @@ export class BranchNode
8180
public readonly root: boolean,
8281
options?: Partial<Options>,
8382
) {
84-
super('branch', uri, view, parent);
83+
super('branch', uri, view, parent, root);
8584

8685
this.updateContext({ repository: repo, branch: branch, root: root });
8786
this._uniqueId = getViewNodeId(this.type, this.context);
@@ -418,8 +417,6 @@ export class BranchNode
418417
}
419418

420419
async getTreeItem(): Promise<TreeItem> {
421-
this.splatted = false;
422-
423420
const parts = await getBranchNodeParts(this.view.container, this.branch, this.current, {
424421
pendingPullRequest: this.getState('pendingPullRequest'),
425422
showAsCommits: this.options.showAsCommits,

src/views/nodes/branchesNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class BranchesNode extends CacheableChildrenViewNode<'branches', ViewsWit
1919
protected override readonly parent: ViewNode,
2020
public readonly repo: Repository,
2121
) {
22-
super('branches', uri, view, parent);
22+
super('branches', uri, view, parent, true);
2323

2424
this.updateContext({ repository: repo });
2525
this._uniqueId = getViewNodeId(this.type, this.context);

0 commit comments

Comments
 (0)