Skip to content

Commit

Permalink
refactor: remove data store
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Sep 24, 2024
1 parent 01faf0d commit 3790691
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 41 deletions.
7 changes: 4 additions & 3 deletions packages/core-common/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { Autowired, ConstructorOf, Domain, INJECTOR_TOKEN, Injector, Provider, Token } from '@opensumi/di';

import { RemoteService, RemoteServiceDataStore } from './remote-service';
import { RemoteService } from './remote-service';
import { RPCProtocol } from './types/rpc';

interface FrontService {
Expand Down Expand Up @@ -38,11 +38,12 @@ export class BasicModule {
contributionProvider: Domain | Domain[];

remoteServices?: (Token | ConstructorOf<RemoteService>)[];
remoteServiceDataStores?: ConstructorOf<RemoteServiceDataStore>[];
}

export const ModuleDependenciesKey = 'dependencies';

export function ModuleDependencies<T extends BasicModule>(dependencies: ConstructorOf<BasicModule>[]) {
return (target) => {
Reflect.defineMetadata('dependencies', dependencies, target);
Reflect.defineMetadata(ModuleDependenciesKey, dependencies, target);
};
}
18 changes: 0 additions & 18 deletions packages/core-common/src/remote-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,6 @@ export abstract class RemoteService<Client = any> {
}
}

/**
* 如何使用
* ```ts
* @Autowired(MessageDataStore, { tag: RemoteServiceDataStore.Session })
* private sessionDataStore: MessageDataStore;
*
* @Autowired(MessageDataStore, { tag: RemoteServiceDataStore.Persisted })
* private persistedDataStore: MessageDataStore;
* ```
*/
@Injectable({ multiple: true })
export abstract class RemoteServiceDataStore {
static Session = 'session';
static Persisted = 'persisted';

readonly _dataStoreBrand = undefined;
}

export function createRemoteServiceChildInjector(injector: Injector, fn: (childInjector: Injector) => void): Injector {
const child = injector.createChild([
{
Expand Down
3 changes: 2 additions & 1 deletion packages/core-node/src/bootstrap/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ContributionProvider,
ILogService,
ILogServiceManager,
ModuleDependenciesKey,
StoragePaths,
SupportLogNamespace,
createContributionProvider,
Expand Down Expand Up @@ -93,7 +94,7 @@ export class ServerApp implements IServerApp {
* 将被依赖但未被加入modules的模块加入到待加载模块最后
*/
public resolveModuleDeps(moduleConstructor: ModuleConstructor, modules: any[]) {
const dependencies = Reflect.getMetadata('dependencies', moduleConstructor) as [];
const dependencies = Reflect.getMetadata(ModuleDependenciesKey, moduleConstructor) as [];
if (dependencies) {
dependencies.forEach((dep) => {
if (modules.indexOf(dep) === -1) {
Expand Down
20 changes: 1 addition & 19 deletions packages/core-node/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RPCServiceCenter, WSChannel, initRPCService } from '@opensumi/ide-conne
import { CommonChannelPathHandler, RPCServiceChannelPath } from '@opensumi/ide-connection/lib/common/server-handler';
import { ElectronChannelHandler } from '@opensumi/ide-connection/lib/electron';
import { CommonChannelHandler, WebSocketHandler, WebSocketServerRoute } from '@opensumi/ide-connection/lib/node';
import { RemoteService, RemoteServiceDataStore, createRemoteServiceChildInjector } from '@opensumi/ide-core-common';
import { RemoteService, createRemoteServiceChildInjector } from '@opensumi/ide-core-common';

import { INodeLogger } from './logger/node-logger';
import { NodeModule } from './node-module';
Expand Down Expand Up @@ -141,24 +141,6 @@ export function bindModuleBackService(
}
}

if (m.remoteServiceDataStores) {
for (const service of m.remoteServiceDataStores) {
// todo: check service is RemoteServiceDataStore

childInjector.addProviders({
token: service,
useClass: service,
tag: RemoteServiceDataStore.Session,
});

injector.addProviders({
token: service,
useClass: service,
tag: RemoteServiceDataStore.Persisted,
});
}
}

if (m.remoteServices) {
for (const service of m.remoteServices) {
const serviceInstance = childInjector.get(service);
Expand Down

0 comments on commit 3790691

Please sign in to comment.