Skip to content

Commit 4da0b36

Browse files
committed
Enough factories to make the once-ler happy
1 parent 6bf3114 commit 4da0b36

File tree

7 files changed

+27
-43
lines changed

7 files changed

+27
-43
lines changed

app/src/lib/components/CommitList.svelte

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { Project } from '$lib/backend/projects';
55
import InsertEmptyCommitAction from '$lib/components/InsertEmptyCommitAction.svelte';
66
import {
7-
getReorderDropzoneManager,
7+
ReorderDropzoneManagerFactory,
88
type ReorderDropzone
99
} from '$lib/dragging/reorderDropzoneManager';
1010
import { getAvatarTooltip } from '$lib/utils/avatar';
@@ -33,7 +33,7 @@
3333
const project = getContext(Project);
3434
const branchController = getContext(BranchController);
3535
36-
const ReorderDropzoneManager = getReorderDropzoneManager();
36+
const reorderDropzoneManagerFactory = getContext(ReorderDropzoneManagerFactory);
3737
3838
// Force the "base" commit lines to update when $branch updates.
3939
let tsKey: number | undefined;
@@ -50,11 +50,10 @@
5050
$: hasIntegratedCommits = $integratedCommits.length > 0;
5151
$: hasRemoteCommits = $remoteCommits.length > 0;
5252
$: hasShadowedCommits = $localCommits.some((c) => c.relatedTo);
53-
$: reorderDropzoneManager = new ReorderDropzoneManager(
54-
[...$localCommits, ...$remoteCommits],
55-
$branch,
56-
branchController
57-
);
53+
$: reorderDropzoneManager = reorderDropzoneManagerFactory.build($branch, [
54+
...$localCommits,
55+
...$remoteCommits
56+
]);
5857
5958
$: forkPoint = $branch.forkPoint;
6059
$: upstreamForkPoint = $branch.upstreamData?.forkPoint;

app/src/lib/components/Dropzone/LineOverlay.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
}
99
1010
const { hovered, activated, yOffsetPx = 0 }: Props = $props();
11-
12-
console.log(yOffsetPx, pxToRem(yOffsetPx));
1311
</script>
1412

1513
<div

app/src/lib/dragging/reorderDropzoneManager.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { DraggableCommit } from '$lib/dragging/draggables';
2-
import { buildConstructorStore } from '$lib/utils/context';
32
import type { BranchController } from '$lib/vbranches/branchController';
43
import type { Branch, Commit } from '$lib/vbranches/types';
54

@@ -22,15 +21,14 @@ import type { Branch, Commit } from '$lib/vbranches/types';
2221
// Exported for type access only
2322
export class ReorderDropzone {
2423
constructor(
24+
private branchController: BranchController,
2525
private branch: Branch,
2626
private index: number,
27-
private indexer: ReorderDropzoneManager,
28-
private branchController: BranchController
27+
private indexer: ReorderDropzoneManager
2928
) {}
3029

3130
accepts(data: any) {
3231
if (!(data instanceof DraggableCommit)) return false;
33-
console.log(this.branch);
3432
if (data.branchId !== this.branch.id) return false;
3533
if (this.indexer.dropzoneCommitOffset(this.index, data.commit.id) === 0) return false;
3634

@@ -51,9 +49,9 @@ export class ReorderDropzoneManager {
5149
private commitIndexes = new Map<string, number>();
5250

5351
constructor(
54-
commits: Commit[],
52+
private branchController: BranchController,
5553
private branch: Branch,
56-
private branchController: BranchController
54+
commits: Commit[]
5755
) {
5856
this.dropzoneIndexes.set('top', 0);
5957

@@ -66,7 +64,7 @@ export class ReorderDropzoneManager {
6664
get topDropzone() {
6765
const index = this.dropzoneIndexes.get('top') ?? 0;
6866

69-
return new ReorderDropzone(this.branch, index, this, this.branchController);
67+
return new ReorderDropzone(this.branchController, this.branch, index, this);
7068
}
7169

7270
dropzoneBelowCommit(commitId: string) {
@@ -76,7 +74,7 @@ export class ReorderDropzoneManager {
7674
throw new Error(`Commit ${commitId} not found in dropzoneIndexes`);
7775
}
7876

79-
return new ReorderDropzone(this.branch, index, this, this.branchController);
77+
return new ReorderDropzone(this.branchController, this.branch, index, this);
8078
}
8179

8280
commitIndex(commitId: string) {
@@ -109,5 +107,10 @@ export class ReorderDropzoneManager {
109107
}
110108
}
111109

112-
export const [getReorderDropzoneManager, setReorderDropzoneManager] =
113-
buildConstructorStore<typeof ReorderDropzoneManager>('ReorderDropzoneManager');
110+
export class ReorderDropzoneManagerFactory {
111+
constructor(private branchController: BranchController) {}
112+
113+
build(branch: Branch, commits: Commit[]) {
114+
return new ReorderDropzoneManager(this.branchController, branch, commits);
115+
}
116+
}

app/src/lib/utils/context.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,3 @@ export function getContextStoreBySymbol<T, S extends Readable<T> = Readable<T>>(
100100
if (!instance) throw new Error(`no instance of \`Readable<${key.toString()}[]>\` in context`);
101101
return instance;
102102
}
103-
104-
export function buildConstructorStore<T extends Class>(
105-
name: string
106-
): [() => T, (constructor: T) => void] {
107-
const identifier = Symbol(name);
108-
109-
return [
110-
() => {
111-
const constructor = svelteGetContext<T | undefined>(identifier);
112-
if (!constructor) throw new Error(`no constructor in context \`${name}\``);
113-
return constructor;
114-
},
115-
(constructor: T) => {
116-
setContext(identifier, constructor);
117-
}
118-
];
119-
}

app/src/routes/+layout.svelte

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
import GlobalSettingsMenuAction from '$lib/components/GlobalSettingsMenuAction.svelte';
1414
import PromptModal from '$lib/components/PromptModal.svelte';
1515
import ShareIssueModal from '$lib/components/ShareIssueModal.svelte';
16-
import {
17-
ReorderDropzoneManager,
18-
setReorderDropzoneManager
19-
} from '$lib/dragging/reorderDropzoneManager';
2016
import { GitHubService } from '$lib/github/service';
2117
import ToastController from '$lib/notifications/ToastController.svelte';
2218
import { RemotesService } from '$lib/remotes/service';
@@ -51,7 +47,6 @@
5147
setContext(User, data.userService.user);
5248
setContext(RemotesService, data.remotesService);
5349
setContext(AIPromptService, data.aiPromptService);
54-
setReorderDropzoneManager(ReorderDropzoneManager);
5550
5651
let shareIssueModal: ShareIssueModal;
5752

app/src/routes/[projectId]/+layout.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import NotOnGitButlerBranch from '$lib/components/NotOnGitButlerBranch.svelte';
1111
import ProblemLoadingRepo from '$lib/components/ProblemLoadingRepo.svelte';
1212
import ProjectSettingsMenuAction from '$lib/components/ProjectSettingsMenuAction.svelte';
13+
import { ReorderDropzoneManagerFactory } from '$lib/dragging/reorderDropzoneManager';
1314
import { HistoryService } from '$lib/history/history';
1415
import { persisted } from '$lib/persisted/persisted';
1516
import * as events from '$lib/utils/events';
@@ -34,7 +35,8 @@
3435
branchService,
3536
branchController,
3637
branchDragActionsFactory,
37-
commitDragActionsFactory
38+
commitDragActionsFactory,
39+
reorderDropzoneManagerFactory
3840
} = data);
3941
4042
$: branchesError = vbranchService.branchesError;
@@ -51,6 +53,7 @@
5153
$: setContext(Project, project);
5254
$: setContext(BranchDragActionsFactory, branchDragActionsFactory);
5355
$: setContext(CommitDragActionsFactory, commitDragActionsFactory);
56+
$: setContext(ReorderDropzoneManagerFactory, reorderDropzoneManagerFactory);
5457
5558
const showHistoryView = persisted(false, 'showHistoryView');
5659

app/src/routes/[projectId]/+layout.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { invoke } from '$lib/backend/ipc';
22
import { BranchDragActionsFactory } from '$lib/branches/dragActions.js';
33
import { BranchService } from '$lib/branches/service';
44
import { CommitDragActionsFactory } from '$lib/commits/dragActions.js';
5+
import { ReorderDropzoneManagerFactory } from '$lib/dragging/reorderDropzoneManager';
56
import { HistoryService } from '$lib/history/history';
67
import { getFetchNotifications } from '$lib/stores/fetches';
78
import { getHeads } from '$lib/stores/head';
@@ -67,6 +68,7 @@ export async function load({ params, parent }) {
6768

6869
const branchDragActionsFactory = new BranchDragActionsFactory(branchController);
6970
const commitDragActionsFactory = new CommitDragActionsFactory(branchController, project);
71+
const reorderDropzoneManagerFactory = new ReorderDropzoneManagerFactory(branchController);
7072

7173
return {
7274
authService,
@@ -83,6 +85,7 @@ export async function load({ params, parent }) {
8385
// These observables are provided for convenience
8486
gbBranchActive$,
8587
branchDragActionsFactory,
86-
commitDragActionsFactory
88+
commitDragActionsFactory,
89+
reorderDropzoneManagerFactory
8790
};
8891
}

0 commit comments

Comments
 (0)