forked from arduino/arduino-ide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage-wrapper.ts
37 lines (35 loc) · 1.12 KB
/
storage-wrapper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { injectable, inject } from 'inversify';
import { StorageService } from '@theia/core/lib/browser/storage-service';
import {
Command,
CommandContribution,
CommandRegistry,
} from '@theia/core/lib/common/command';
/**
* This is a workaround to break cycles in the dependency injection. Provides commands for `setData` and `getData`.
*/
@injectable()
export class StorageWrapper implements CommandContribution {
@inject(StorageService)
protected storageService: StorageService;
registerCommands(commands: CommandRegistry): void {
commands.registerCommand(StorageWrapper.Commands.GET_DATA, {
execute: (key: string, defaultValue?: any) =>
this.storageService.getData(key, defaultValue),
});
commands.registerCommand(StorageWrapper.Commands.SET_DATA, {
execute: (key: string, value: any) =>
this.storageService.setData(key, value),
});
}
}
export namespace StorageWrapper {
export namespace Commands {
export const SET_DATA: Command = {
id: 'arduino-store-wrapper-set',
};
export const GET_DATA: Command = {
id: 'arduino-store-wrapper-get',
};
}
}