Skip to content

Commit

Permalink
transform in singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
carolhmj committed Sep 26, 2023
1 parent 93f70c0 commit 4285f50
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/dev/core/src/FlowGraph/flowGraphEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,34 @@ export class IFlowGraphEngineConfiguration {
scene: Scene;
}
/**
* The FlowGraphEngine class holds all of the existing flow graphs and is responsible for creating new ones.
* The FlowGraphEngine singleton class holds all of the existing flow graphs and is responsible for creating new ones.
* It also handles communication between them through an Event Coordinator
*/
export class FlowGraphEngine {
private readonly _eventCoordinator: FlowGraphEventCoordinator;
private readonly _flowGraphs: FlowGraph[] = [];
/**
* The instance of the flow graph engine
*/
private static instance: FlowGraphEngine;

constructor(private _config: IFlowGraphEngineConfiguration) {
private constructor() {
this._eventCoordinator = new FlowGraphEventCoordinator();
}

public static getInstance(): FlowGraphEngine {
if (!FlowGraphEngine.instance) {
FlowGraphEngine.instance = new FlowGraphEngine();
}
return FlowGraphEngine.instance;
}

/**
* Creates a new flow graph and adds it to the list of existing flow graphs
* @returns a new flow graph
*/
createGraph(): FlowGraph {
const graph = new FlowGraph({ scene: this._config.scene, eventCoordinator: this._eventCoordinator });
createGraph(scene: Scene): FlowGraph {
const graph = new FlowGraph({ scene, eventCoordinator: this._eventCoordinator });
this._flowGraphs.push(graph);
return graph;
}
Expand Down

0 comments on commit 4285f50

Please sign in to comment.