Minor code reorg

This commit is contained in:
Eric Amodio
2020-06-29 15:16:08 -04:00
parent 2183e2db8a
commit 6a6876b023
6 changed files with 42 additions and 32 deletions

View File

@@ -370,31 +370,3 @@ export class ChangeStore implements IChangeStore, IWritableChangeStore {
await this.memento.update(`${workingFileKeyPrefix}${uri.toString()}`, undefined);
}
}
const contextKeyPrefix = 'github.context|';
export class ContextStore<T> {
private _onDidChange = new EventEmitter<Uri>();
get onDidChange(): Event<Uri> {
return this._onDidChange.event;
}
constructor(private readonly memento: Memento, private readonly scheme: string) { }
delete(uri: Uri) {
return this.set(uri, undefined);
}
get(uri: Uri): T | undefined {
return this.memento.get<T>(`${contextKeyPrefix}${uri.toString()}`);
}
async set(uri: Uri, context: T | undefined) {
if (uri.scheme !== this.scheme) {
throw new Error(`Invalid context scheme: ${uri.scheme}`);
}
await this.memento.update(`${contextKeyPrefix}${uri.toString()}`, context);
this._onDidChange.fire(uri);
}
}

View File

@@ -0,0 +1,36 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { Event, EventEmitter, Memento, Uri } from 'vscode';
export const contextKeyPrefix = 'github.context|';
export class ContextStore<T> {
private _onDidChange = new EventEmitter<Uri>();
get onDidChange(): Event<Uri> {
return this._onDidChange.event;
}
constructor(private readonly memento: Memento, private readonly scheme: string) { }
delete(uri: Uri) {
return this.set(uri, undefined);
}
get(uri: Uri): T | undefined {
return this.memento.get<T>(`${contextKeyPrefix}${uri.toString()}`);
}
async set(uri: Uri, context: T | undefined) {
if (uri.scheme !== this.scheme) {
throw new Error(`Invalid context scheme: ${uri.scheme}`);
}
await this.memento.update(`${contextKeyPrefix}${uri.toString()}`, context);
this._onDidChange.fire(uri);
}
}

View File

@@ -4,7 +4,8 @@
*--------------------------------------------------------------------------------------------*/
import { ExtensionContext, Uri, workspace } from 'vscode';
import { ChangeStore, ContextStore } from './stores';
import { ChangeStore } from './changeStore';
import { ContextStore } from './contextStore';
import { VirtualFS } from './fs';
import { GitHubApiContext, GitHubApi } from './github/api';
import { GitHubFS } from './github/fs';

View File

@@ -26,7 +26,8 @@ import {
Uri,
workspace,
} from 'vscode';
import { ContextStore, IWritableChangeStore } from './stores';
import { IWritableChangeStore } from './changeStore';
import { ContextStore } from './contextStore';
import { GitHubApiContext } from './github/api';
const emptyDisposable = { dispose: () => { /* noop */ } };

View File

@@ -7,8 +7,8 @@ import { authentication, AuthenticationSession, Disposable, Event, EventEmitter,
import { graphql } from '@octokit/graphql';
import { Octokit } from '@octokit/rest';
import { fromGitHubUri } from './fs';
import { ContextStore } from '../contextStore';
import { Iterables } from '../iterables';
import { ContextStore } from '../stores';
export const shaRegex = /^[0-9a-f]{40}$/;

View File

@@ -6,7 +6,7 @@
'use strict';
import { CancellationToken, commands, Disposable, scm, SourceControl, SourceControlResourceGroup, SourceControlResourceState, Uri, window, workspace } from 'vscode';
import * as nls from 'vscode-nls';
import { IChangeStore } from './stores';
import { IChangeStore } from './changeStore';
import { GitHubApi, CommitOperation } from './github/api';
import { getRelativePath } from './extension';