Skip to content

Commit

Permalink
コメント整理
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba committed Jan 3, 2025
1 parent 08ff0ac commit 75d7578
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
48 changes: 25 additions & 23 deletions src/infrastructures/EngineConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface IEngineConnectorFactory {
instance: (host: string) => DefaultApiInterface;
}

// 通常エンジン
const OpenAPIEngineConnectorFactoryImpl = (): IEngineConnectorFactory => {
const instanceMapper: Record<string, DefaultApiInterface> = {};
return {
Expand All @@ -23,11 +24,10 @@ const OpenAPIEngineConnectorFactoryImpl = (): IEngineConnectorFactory => {
},
};
};

/** エンジン */
export const OpenAPIEngineConnectorFactory =
OpenAPIEngineConnectorFactoryImpl();

// モック用エンジン
const OpenAPIMockEngineConnectorFactoryImpl = (): IEngineConnectorFactory => {
let mockInstance: DefaultApiInterface | undefined;
return {
Expand All @@ -39,28 +39,30 @@ const OpenAPIMockEngineConnectorFactoryImpl = (): IEngineConnectorFactory => {
},
};
};

/** モック用エンジン */
export const OpenAPIMockEngineConnectorFactory =
OpenAPIMockEngineConnectorFactoryImpl();

/** モック用エンジンのURLは `mock://mock` とする */
export const mockUrlParams = {
protocol: "mock:",
hostname: "mock",
port: "",
pathname: "",
} satisfies EngineUrlParams;
// 通常エンジンとモック用エンジンの両対応
// モック用エンジンのURLのときはモックを、そうじゃないときは通常エンジンを返す。
const OpenAPIEngineAndMockConnectorFactoryImpl =
(): IEngineConnectorFactory => {
// モック用エンジンのURLは `mock://mock` とする
const mockUrlParams: EngineUrlParams = {
protocol: "mock:",
hostname: "mock",
port: "",
pathname: "",
};

/**
* モック用エンジンのURLのときはモックを、そうじゃないときは通常エンジンを返す。
*/
export const OpenAPIEngineAndMockConnectorFactory: IEngineConnectorFactory = {
instance: (host: string) => {
if (host == createEngineUrl(mockUrlParams)) {
return OpenAPIMockEngineConnectorFactory.instance(host);
} else {
return OpenAPIEngineConnectorFactory.instance(host);
}
},
};
return {
instance: (host: string) => {
if (host == createEngineUrl(mockUrlParams)) {
return OpenAPIMockEngineConnectorFactory.instance(host);
} else {
return OpenAPIEngineConnectorFactory.instance(host);
}
},
};
};
export const OpenAPIEngineAndMockConnectorFactory =
OpenAPIEngineAndMockConnectorFactoryImpl();
14 changes: 8 additions & 6 deletions src/store/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ export const convertAudioQueryFromEngineToEditor = (
};
};

// 製品PC版以外はモックエンジンも使えるようする
const ConnectorFactory =
isElectron && isProduction
? OpenAPIEngineConnectorFactory
: OpenAPIEngineAndMockConnectorFactory;
export const proxyStore = proxyStoreCreator(ConnectorFactory);
// 製品PC版は通常エンジンのみを、それ以外はモックエンジンも使えるようする
const getConnectorFactory = () => {
if (isElectron && isProduction) {
return OpenAPIEngineConnectorFactory;
}
return OpenAPIEngineAndMockConnectorFactory;
};
export const proxyStore = proxyStoreCreator(getConnectorFactory());

0 comments on commit 75d7578

Please sign in to comment.