mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-28 22:03:30 +03:00
Set branch/commit stores only once on init
- initialse context stores with undefined - simpler logic for reducing outbound requests/flicker
This commit is contained in:
parent
753f3a2813
commit
7a4c625781
@ -30,13 +30,13 @@
|
||||
// TODO: Update store here rather than reset it
|
||||
$: ownershipStore.set(Ownership.fromBranch(branch));
|
||||
|
||||
const branchStore = createContextStore(Branch, branch);
|
||||
const branchStore = createContextStore(Branch, undefined);
|
||||
$: branchStore.set(branch);
|
||||
|
||||
const localCommits = createLocalContextStore(branch.localCommits);
|
||||
const localCommits = createLocalContextStore(undefined);
|
||||
$: localCommits.set(branch.localCommits);
|
||||
|
||||
const remoteCommits = createRemoteContextStore(branch.remoteCommits);
|
||||
const remoteCommits = createRemoteContextStore(undefined);
|
||||
$: remoteCommits.set(branch.remoteCommits);
|
||||
|
||||
// Set the store immediately so it can be updated later.
|
||||
|
@ -13,6 +13,7 @@
|
||||
import { openExternalUrl } from '$lib/utils/url';
|
||||
import { BaseBranchService } from '$lib/vbranches/baseBranch';
|
||||
import { Branch } from '$lib/vbranches/types';
|
||||
import { distinctUntilChanged } from 'rxjs';
|
||||
import { onDestroy } from 'svelte';
|
||||
import type { ChecksStatus, DetailedPullRequest } from '$lib/github/types';
|
||||
import type { ComponentColor } from '$lib/vbranches/types';
|
||||
@ -43,8 +44,12 @@
|
||||
let checksStatus: ChecksStatus | null | undefined = undefined;
|
||||
let lastDetailsFetch: Readable<string> | undefined;
|
||||
|
||||
$: pr$ = githubService.getPr$($branch.upstreamName);
|
||||
$: if ($branch && $pr$) updateDetailsAndChecks();
|
||||
$: pr$ = githubService.getPr$($branch.upstreamName).pipe(
|
||||
distinctUntilChanged((prev, curr) => {
|
||||
return prev?.modifiedAt.getTime() === curr?.modifiedAt.getTime();
|
||||
})
|
||||
);
|
||||
$: if ($pr$) updateDetailsAndChecks();
|
||||
|
||||
$: checksTagInfo = getChecksTagInfo(checksStatus, isFetchingChecks);
|
||||
$: infoProps = getInfoMessageInfo(detailedPr, mergeableState, checksStatus, isFetchingChecks);
|
||||
|
@ -52,8 +52,8 @@ export function maybeGetContextStore<
|
||||
*/
|
||||
export function createContextStore<T extends Class>(
|
||||
key: T | symbol,
|
||||
value: InstanceType<T>
|
||||
): Writable<InstanceType<T>> {
|
||||
value: InstanceType<T> | undefined
|
||||
): Writable<InstanceType<T> | undefined> {
|
||||
const instance = svelteGetContext<Writable<InstanceType<T>> | undefined>(key);
|
||||
if (instance) {
|
||||
throw new Error('Context store already defined for key: ' + key.toString());
|
||||
@ -78,13 +78,13 @@ export function createContextStore<T extends Class>(
|
||||
*/
|
||||
export function buildContextStore<T, S extends Readable<T> = Readable<T>>(
|
||||
name: string
|
||||
): [() => S, (value: T) => Writable<T>] {
|
||||
): [() => S, (value: T | undefined) => Writable<T>] {
|
||||
const identifier = Symbol(name);
|
||||
return [
|
||||
() => {
|
||||
return getContextStoreBySymbol<T, S>(identifier);
|
||||
},
|
||||
(value: T) => {
|
||||
(value: T | undefined) => {
|
||||
return createContextStore(identifier, value);
|
||||
}
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user