changed my mind about union types

This commit is contained in:
Kiril Videlov 2023-06-27 09:43:32 +02:00 committed by Kiril Videlov
parent ec36f0c494
commit 0a45945738
3 changed files with 10 additions and 11 deletions

View File

@ -5,16 +5,15 @@
import type { Branch } from './types';
import { invoke } from '@tauri-apps/api';
import vbranches from './vbranches';
import { Value, Loadable } from 'svelte-loadable-store';
import type { Readable } from '@square/svelte-store';
import { Value } from 'svelte-loadable-store';
export let data: PageData;
let { projectId, target, remoteBranches, remoteBranchesData } = data;
const branchStore = vbranches(projectId) as Readable<Loadable<Branch[]>>;
$: branches = $branchStore.isLoading
const virtualBranches = vbranches(projectId);
$: branches = $virtualBranches.isLoading
? []
: Value.isValue($branchStore.value)
? $branchStore.value
: Value.isValue($virtualBranches.value)
? $virtualBranches.value
: [];
let targetChoice = 'origin/master'; // prob should check if it exists
@ -40,7 +39,7 @@
{#if target}
<div class="flex w-full max-w-full">
<Tray bind:branches {target} {projectId} remoteBranches={remoteBranchesData} />
<Board bind:branches {projectId} {branchStore} on:newBranch={handleNewBranch} />
<Board bind:branches {projectId} {virtualBranches} on:newBranch={handleNewBranch} />
</div>
{:else}
<div class="m-auto flex flex-col space-y-2">

View File

@ -9,7 +9,7 @@
export let projectId: string;
export let branches: Branch[];
export let branchStore: VirtualBrancher;
export let virtualBranches: VirtualBrancher;
const dispatch = createEventDispatcher();
const newBranchClass = 'new-branch-active';
@ -31,7 +31,7 @@
function handleUpdateRequest() {
// TODO: pass this as prop to components and refresh whenever we perform updates
branchStore.refresh();
virtualBranches.refresh();
}
</script>

View File

@ -6,7 +6,7 @@ import { plainToInstance } from 'class-transformer';
import type { Readable, Writable } from '@square/svelte-store';
/** Virtual Branch interface with custom operations on top of subscribing */
export interface VirtualBrancher {
export interface VirtualBrancher extends Readable<Loadable<Branch[]>> {
/**
* Force re-fetch of the branches. Exists temporarily until we have all mutations on this interface.
*/
@ -16,7 +16,7 @@ export interface VirtualBrancher {
const cache: Record<string, Writable<Loadable<Branch[]>>> = {};
export default (projectId: string): VirtualBrancher | Readable<Loadable<Branch[]>> => {
export default (projectId: string): VirtualBrancher => {
if (projectId in cache) {
const store = cache[projectId];
return {