Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[storage-service] applied feedback from #525 #537

Merged
merged 1 commit into from
Sep 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/core/src/browser/storage-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { LocalStorageService, StorageService } from './storage-service';
import * as assert from 'assert';
import { expect } from 'chai';
import { TestLogger } from '../common/test/test-logger';

let storageService: StorageService;
Expand All @@ -21,24 +21,24 @@ describe("storage-service", () => {
storageService.setData('foo', {
test: 'foo'
});
assert(await storageService.getData('bar', 'bar') === 'bar');
assert((await storageService.getData('foo', {
expect(await storageService.getData('bar', 'bar')).equals('bar');
expect((await storageService.getData('foo', {
test: 'bar'
})).test === 'foo');
})).test).equals('foo');
});

it("removes data", async () => {
storageService.setData('foo', {
test: 'foo'
});
assert((await storageService.getData('foo', {
expect((await storageService.getData('foo', {
test: 'bar'
})).test === 'foo');
})).test).equals('foo');

storageService.setData('foo', undefined);
assert((await storageService.getData('foo', {
expect((await storageService.getData('foo', {
test: 'bar'
})).test === 'bar');
})).test).equals('bar');
});

});
5 changes: 3 additions & 2 deletions packages/core/src/browser/storage-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface StorageService {
* returns the data stored for the given key or the provided default value if nothing is stored for the given key.
*/
getData<T>(key: string, defaultValue: T): Promise<T>;
getData<T>(key: string): Promise<T | undefined>;
}

interface LocalStorage {
Expand All @@ -50,10 +51,10 @@ export class LocalStorageService implements StorageService {
} else {
delete this.storage[this.prefix(key)];
}
return Promise.resolve(undefined);
return Promise.resolve();
}

getData<T>(key: string, defaultValue: T): Promise<T> {
getData<T>(key: string, defaultValue?: T): Promise<T | undefined> {
const result = this.storage[this.prefix(key)];
if (result === undefined) {
return Promise.resolve(defaultValue);
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/browser/widget-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/


import * as assert from 'assert';
import { expect } from 'chai';
import { TestLogger } from '../common/test/test-logger';
import { WidgetManager, WidgetFactory } from './widget-manager';
import { Widget } from '@phosphor/widgets';
Expand Down Expand Up @@ -51,9 +51,8 @@ describe("widget-manager", () => {
it("creates and caches widgets", async () => {
const wA = await widgetManager.getOrCreateWidget('test', 'widgetA');
const wB = await widgetManager.getOrCreateWidget('test', 'widgetB');
assert.notStrictEqual(wA, wB);
assert.strictEqual(wA, await widgetManager.getOrCreateWidget('test', 'widgetA'));
expect(wA).not.equals(wB);
expect(wA).equals(await widgetManager.getOrCreateWidget('test', 'widgetA'));
});

});

8 changes: 4 additions & 4 deletions packages/workspace/src/browser/workspace-storage-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ export class WorkspaceStorageService implements StorageService {
if (!this.root) {
await this.rootPromise;
}
const fullKey = this.getKey(key);
const fullKey = this.prefixWorkspaceURI(key);
return this.storageService.setData(fullKey, data);
}

async getData<T>(key: string, defaultValue: T): Promise<T> {
async getData<T>(key: string, defaultValue?: T): Promise<T | undefined> {
await this.rootPromise;
const fullKey = this.getKey(key);
const fullKey = this.prefixWorkspaceURI(key);
return this.storageService.getData(fullKey, defaultValue);
}

protected getKey(originalKey: string): string {
protected prefixWorkspaceURI(originalKey: string): string {
return this.root.uri + ":" + originalKey;
}
}