Skip to content

Commit 6a6876b

Browse files
author
Eric Amodio
committed
Minor code reorg
1 parent 2183e2d commit 6a6876b

6 files changed

Lines changed: 42 additions & 32 deletions

File tree

extensions/github-browser/src/stores.ts renamed to extensions/github-browser/src/changeStore.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -370,31 +370,3 @@ export class ChangeStore implements IChangeStore, IWritableChangeStore {
370370
await this.memento.update(`${workingFileKeyPrefix}${uri.toString()}`, undefined);
371371
}
372372
}
373-
374-
const contextKeyPrefix = 'github.context|';
375-
376-
export class ContextStore<T> {
377-
private _onDidChange = new EventEmitter<Uri>();
378-
get onDidChange(): Event<Uri> {
379-
return this._onDidChange.event;
380-
}
381-
382-
constructor(private readonly memento: Memento, private readonly scheme: string) { }
383-
384-
delete(uri: Uri) {
385-
return this.set(uri, undefined);
386-
}
387-
388-
get(uri: Uri): T | undefined {
389-
return this.memento.get<T>(`${contextKeyPrefix}${uri.toString()}`);
390-
}
391-
392-
async set(uri: Uri, context: T | undefined) {
393-
if (uri.scheme !== this.scheme) {
394-
throw new Error(`Invalid context scheme: ${uri.scheme}`);
395-
}
396-
397-
await this.memento.update(`${contextKeyPrefix}${uri.toString()}`, context);
398-
this._onDidChange.fire(uri);
399-
}
400-
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
import { Event, EventEmitter, Memento, Uri } from 'vscode';
8+
9+
export const contextKeyPrefix = 'github.context|';
10+
11+
export class ContextStore<T> {
12+
private _onDidChange = new EventEmitter<Uri>();
13+
get onDidChange(): Event<Uri> {
14+
return this._onDidChange.event;
15+
}
16+
17+
constructor(private readonly memento: Memento, private readonly scheme: string) { }
18+
19+
delete(uri: Uri) {
20+
return this.set(uri, undefined);
21+
}
22+
23+
get(uri: Uri): T | undefined {
24+
return this.memento.get<T>(`${contextKeyPrefix}${uri.toString()}`);
25+
}
26+
27+
28+
async set(uri: Uri, context: T | undefined) {
29+
if (uri.scheme !== this.scheme) {
30+
throw new Error(`Invalid context scheme: ${uri.scheme}`);
31+
}
32+
33+
await this.memento.update(`${contextKeyPrefix}${uri.toString()}`, context);
34+
this._onDidChange.fire(uri);
35+
}
36+
}

extensions/github-browser/src/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*--------------------------------------------------------------------------------------------*/
55

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

extensions/github-browser/src/fs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import {
2626
Uri,
2727
workspace,
2828
} from 'vscode';
29-
import { ContextStore, IWritableChangeStore } from './stores';
29+
import { IWritableChangeStore } from './changeStore';
30+
import { ContextStore } from './contextStore';
3031
import { GitHubApiContext } from './github/api';
3132

3233
const emptyDisposable = { dispose: () => { /* noop */ } };

extensions/github-browser/src/github/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { authentication, AuthenticationSession, Disposable, Event, EventEmitter,
77
import { graphql } from '@octokit/graphql';
88
import { Octokit } from '@octokit/rest';
99
import { fromGitHubUri } from './fs';
10+
import { ContextStore } from '../contextStore';
1011
import { Iterables } from '../iterables';
11-
import { ContextStore } from '../stores';
1212

1313
export const shaRegex = /^[0-9a-f]{40}$/;
1414

extensions/github-browser/src/scm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'use strict';
77
import { CancellationToken, commands, Disposable, scm, SourceControl, SourceControlResourceGroup, SourceControlResourceState, Uri, window, workspace } from 'vscode';
88
import * as nls from 'vscode-nls';
9-
import { IChangeStore } from './stores';
9+
import { IChangeStore } from './changeStore';
1010
import { GitHubApi, CommitOperation } from './github/api';
1111
import { getRelativePath } from './extension';
1212

0 commit comments

Comments
 (0)