Skip to content

Commit bd4340e

Browse files
committed
Removed unnecessary dependencies
Only a half of TextResourceUtil requires `getCurrentDate` function. It's been forcing dependants to setup the module with unnecessary dependencies.
1 parent 818eb78 commit bd4340e

File tree

6 files changed

+17
-37
lines changed

6 files changed

+17
-37
lines changed

src/lib/bootstrapper-factory.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ export default class BootstrapperFactory {
2323
new Clipboard(clipboardy, process.platform),
2424
() => new Date()
2525
);
26-
const contentProvider = new ContentProvider(
27-
selectionInfoRegistry,
28-
normalisationRuleStore,
29-
() => new Date()
30-
);
26+
const contentProvider = new ContentProvider(selectionInfoRegistry, normalisationRuleStore);
3127
return new Bootstrapper(commandFactory, contentProvider, vscode, logger);
3228
}
3329

src/lib/content-provider.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ export default class ContentProvider implements TextDocumentContentProvider {
1111
private readonly textProcessRuleApplier: TextProcessRuleApplier;
1212

1313
constructor(selectionInfoRegistry: SelectionInfoRegistry,
14-
normalisationRuleStore: NormalisationRuleStore,
15-
getCurrentDate: () => Date) {
14+
normalisationRuleStore: NormalisationRuleStore) {
1615
this.selectionInfoRegistry = selectionInfoRegistry;
17-
this.textResourceUtil = new TextResourceUtil(getCurrentDate);
16+
this.textResourceUtil = new TextResourceUtil();
1817
this.textProcessRuleApplier = new TextProcessRuleApplier(normalisationRuleStore);
1918
}
2019

src/lib/diff-presenter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import NormalisationRuleStore from './normalisation-rule-store';
22
import SelectionInfoRegistry from './selection-info-registry';
3-
import TextResourceUtil from './text-resource-util';
3+
import {makeUriString} from './text-resource-util';
44
import CommandAdaptor from './adaptors/command';
55
import DiffTitleBuilder from './diff-title-builder';
66

77
export default class DiffPresenter {
8-
private readonly textResourceUtil: TextResourceUtil;
8+
private readonly getCurrentDate: () => Date;
99
private readonly diffTitleBuilder: DiffTitleBuilder;
1010
private readonly commandAdaptor: CommandAdaptor;
1111

1212
constructor(selectionInfoRegistry: SelectionInfoRegistry,
1313
normalisationRuleStore: NormalisationRuleStore,
1414
commandAdaptor: CommandAdaptor,
1515
getCurrentDate: () => Date) {
16-
this.textResourceUtil = new TextResourceUtil(getCurrentDate);
16+
this.getCurrentDate = getCurrentDate;
1717
this.diffTitleBuilder = new DiffTitleBuilder(normalisationRuleStore, selectionInfoRegistry);
1818
this.commandAdaptor = commandAdaptor;
1919
}
2020

2121
takeDiff(textKey1: string, textKey2: string) {
22-
const getUri = (textKey: string) => this.textResourceUtil.getUri(textKey);
22+
const getUri = (textKey: string) => makeUriString(textKey, this.getCurrentDate());
2323
const title = this.diffTitleBuilder.build(textKey1, textKey2);
2424
return this.commandAdaptor.executeCommand('vscode.diff', getUri(textKey1), getUri(textKey2), title);
2525
}

src/lib/text-resource-util.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
import * as vscode from 'vscode';
22
import {EXTENSION_SCHEME} from './const';
33

4-
export default class TextResourceUtil {
5-
private readonly getCurrentDate: () => Date;
6-
7-
constructor(getCurrentDate: () => Date) {
8-
this.getCurrentDate = getCurrentDate;
9-
}
4+
export const makeUriString = (textKey: string, timestamp: Date) =>
5+
`${EXTENSION_SCHEME}:text/${textKey}?_ts=${timestamp.getTime()}`; // `_ts` to avoid cache
106

11-
getUri(textKey: string) {
12-
const timestamp = this.getCurrentDate().getTime();
13-
return `${EXTENSION_SCHEME}:text/${textKey}?_ts=${timestamp}`; // `_ts` to avoid cache
14-
}
7+
export default class TextResourceUtil {
158

169
getTextKey(uri: vscode.Uri): string {
1710
const match = uri.path.match(/^text\/([a-z\d]+)/)!;

src/test/lib/content-provider.test.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ suite('ContentProvider', () => {
1818
const normalisationRuleStore = mockType<NormalisationRuleStore>({
1919
activeRules: [{match: '_', replaceWith: ':'}]
2020
});
21-
const contentProvider = new ContentProvider(
22-
selectionInfoRegistry,
23-
normalisationRuleStore,
24-
() => new Date()
25-
);
21+
const contentProvider = new ContentProvider(selectionInfoRegistry, normalisationRuleStore);
2622

2723
test('it extracts text key from the given uri and uses it to retrieve text', () => {
2824
const uri = mockType<vscode.Uri>({path: 'text/key1'});
@@ -37,11 +33,7 @@ suite('ContentProvider', () => {
3733

3834
suite('When normalisation rules are NOT given', () => {
3935
const normalisationRuleStore = mockType<NormalisationRuleStore>({activeRules: []});
40-
const contentProvider = new ContentProvider(
41-
selectionInfoRegistry,
42-
normalisationRuleStore,
43-
() => new Date()
44-
);
36+
const contentProvider = new ContentProvider(selectionInfoRegistry, normalisationRuleStore);
4537

4638
test('it returns the registered text as is', () => {
4739
const uri = mockType<vscode.Uri>({path: 'text/key1'});

src/test/lib/text-resource-util.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import TextResourceUtil from '../../lib/text-resource-util';
1+
import TextResourceUtil, {makeUriString} from '../../lib/text-resource-util';
22
import * as assert from 'assert';
33

44
suite('TextResourceUtil', () => {
5-
const getCurrentDateFn = () => new Date('2016-06-15T11:43:00Z');
6-
const textResourceUtil = new TextResourceUtil(getCurrentDateFn);
5+
const date = new Date('2016-06-15T11:43:00Z');
6+
const textResourceUtil = new TextResourceUtil();
77

8-
suite('#getUri', () => {
8+
suite('#makeUriString', () => {
99
test('it converts a given text key into an uri', () => {
10-
assert.deepEqual(textResourceUtil.getUri('reg1'), 'partialdiff:text/reg1?_ts=1465990980000');
10+
assert.deepEqual(makeUriString('reg1', date), 'partialdiff:text/reg1?_ts=1465990980000');
1111
});
1212
});
1313

0 commit comments

Comments
 (0)