-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(view): rename messages, abstract port usages.
- Loading branch information
Showing
12 changed files
with
80 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,65 @@ | ||
import { injectable } from "tsyringe"; | ||
|
||
import type { ClusterNode, EngineCommand, EngineCommandNames } from "types"; | ||
import type { EngineMessage, EngineMessageEvent } from "types/EngineMessage"; | ||
import type { ClusterNode, IDEMessage, IDEMessageEvent } from "types"; | ||
import type { IDESentEvents } from "types/IDESentEvents"; | ||
|
||
import fakeData from "../fake-assets/cluster-nodes.json"; | ||
|
||
import type IDEPort from "./IDEPort"; | ||
|
||
@injectable() | ||
export default class FakeIDEAdapter implements IDEPort { | ||
public addAllEventListener(fetchAnalyzedData: (analyzedData: ClusterNode[]) => void) { | ||
const onReceiveMessage = (e: EngineMessageEvent): void => { | ||
const response = e.data; | ||
if (response.command === "fetchAnalyzedData") { | ||
const fetchedData = response.payload as unknown as ClusterNode[]; | ||
fetchAnalyzedData(fetchedData); | ||
public addIDESentEventListener(events: IDESentEvents) { | ||
const onReceiveMessage = (e: IDEMessageEvent): void => { | ||
const responseMessage = e.data; | ||
if (responseMessage.command === "fetchAnalyzedData") { | ||
const fetchedData = responseMessage.payload as unknown as ClusterNode[]; | ||
events.fetchAnalyzedData(fetchedData); | ||
} | ||
}; | ||
|
||
window.addEventListener("message", onReceiveMessage); | ||
} | ||
|
||
public sendFetchAnalyzedDataCommand() { | ||
const command: EngineCommand = { | ||
public sendFetchAnalyzedDataMessage() { | ||
const message: IDEMessage = { | ||
command: "fetchAnalyzedData", | ||
}; | ||
setTimeout(() => { | ||
this.executeCommand(command); | ||
this.sendMessageToMe(message); | ||
}, 3000); | ||
} | ||
|
||
public setPrimaryColor(color: string) { | ||
sessionStorage.setItem("PRIMARY_COLOR", color); | ||
const command: EngineCommand = { | ||
const message: IDEMessage = { | ||
command: "updatePrimaryColor", | ||
}; | ||
this.executeCommand(command); | ||
this.sendMessageToMe(message); | ||
} | ||
|
||
private getResponseMessage(commandName: EngineCommandNames) { | ||
switch (commandName) { | ||
private convertMessage(message: IDEMessage) { | ||
const { command } = message; | ||
|
||
switch (command) { | ||
case "fetchAnalyzedData": | ||
return { | ||
command: commandName, | ||
command: command, | ||
payload: fakeData as unknown as string, | ||
}; | ||
case "updatePrimaryColor": | ||
return { | ||
command: commandName, | ||
command: command, | ||
payload: sessionStorage.getItem("PRIMARY_COLOR") as string, | ||
}; | ||
default: | ||
return { | ||
command: commandName, | ||
command: command, | ||
}; | ||
} | ||
} | ||
|
||
private executeCommand(command: EngineCommand) { | ||
const message: EngineMessage = this.getResponseMessage(command.command); | ||
window.postMessage(message); | ||
private sendMessageToMe(message: IDEMessage) { | ||
window.postMessage(this.convertMessage(message)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import type { ClusterNode } from "types"; | ||
import type { IDESentEvents } from "types/IDESentEvents"; | ||
|
||
export type IDEMessage = { | ||
command: string; | ||
uri: string; | ||
}; | ||
|
||
export default interface IDEPort { | ||
addAllEventListener: (fetchAnalyzedData: (analyzedData: ClusterNode[]) => void) => void; | ||
sendFetchAnalyzedDataCommand: () => void; | ||
addIDESentEventListener: (apiCallbacks: IDESentEvents) => void; | ||
sendFetchAnalyzedDataMessage: () => void; | ||
setPrimaryColor: (color: string) => void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { container } from "tsyringe"; | ||
|
||
import type IDEPort from "ide/IDEPort"; | ||
|
||
const ideAdapter = container.resolve<IDEPort>("IDEAdapter"); | ||
|
||
export const setPrimaryColor = (color: string) => { | ||
ideAdapter.setPrimaryColor(color); | ||
}; | ||
|
||
export const sendFetchAnalyzedDataCommand = () => { | ||
ideAdapter.sendFetchAnalyzedDataMessage(); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export type IDEMessage = { | ||
command: IDEMessageCommandNames; | ||
payload?: string; | ||
}; | ||
|
||
export interface IDEMessageEvent extends MessageEvent { | ||
data: IDEMessage; | ||
} | ||
|
||
export type IDEMessageCommandNames = "fetchAnalyzedData" | "getBranchList" | "updatePrimaryColor"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { ClusterNode } from "types"; | ||
|
||
// triggered by ide response | ||
export type IDESentEvents = { | ||
fetchAnalyzedData: (analyzedData: ClusterNode[]) => void; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export * from "./global"; | ||
export * from "./NodeTypes.temp"; | ||
export * from "./EngineCommand"; | ||
export * from "./EngineMessage"; | ||
export * from "./IDEMessage"; | ||
export * from "./Author"; |