forked from PrincetonUniversity/PsyNeuLinkView
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#40 model singleton and changes required for redux
- Loading branch information
Showing
7 changed files
with
152 additions
and
69 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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { PNLClasses } from '../constants'; | ||
import { generateMetaGraph } from './utils'; | ||
import ModelInterpreter from './Interpreter'; | ||
import { ComponentsMap } from '@metacell/meta-diagram'; | ||
import { MetaGraph } from '../components/graph/MetaGraph'; | ||
import { MetaLink, MetaNode } from '@metacell/meta-diagram'; | ||
import Composition from '../components/views/compositions/Composition'; | ||
import GenericMechanism from '../components/views/mechanisms/GenericMechanism'; | ||
import CustomLinkWidget from '../components/views/projections/CustomLinkWidget'; | ||
|
||
export default class ModelSingleton { | ||
private static instance: ModelSingleton; | ||
private static componentsMap: any; | ||
private static interpreter: ModelInterpreter; | ||
private static model: Object; | ||
private static metaModel: { [key: string]: Array<MetaNode|MetaLink> }; | ||
private static metaGraph: MetaGraph; | ||
|
||
private constructor(inputModel: any) { | ||
ModelSingleton.componentsMap = new ComponentsMap(new Map(), new Map()); | ||
ModelSingleton.componentsMap.nodes.set(PNLClasses.COMPOSITION, Composition); | ||
ModelSingleton.componentsMap.nodes.set(PNLClasses.MECHANISM, GenericMechanism); | ||
ModelSingleton.componentsMap.links.set(PNLClasses.PROJECTION, CustomLinkWidget); | ||
|
||
ModelSingleton.interpreter = new ModelInterpreter(inputModel); | ||
ModelSingleton.model = ModelSingleton.interpreter.getModel(); | ||
ModelSingleton.metaModel = ModelSingleton.interpreter.getMetaModel(); | ||
|
||
ModelSingleton.metaGraph = generateMetaGraph([ | ||
...ModelSingleton.metaModel[PNLClasses.COMPOSITION], | ||
...ModelSingleton.metaModel[PNLClasses.MECHANISM], | ||
]); | ||
// const links = ModelSingleton.metaModel[PNLClasses.PROJECTION].filter((item: any) => {return (item instanceof MetaLink)}); | ||
// @ts-ignore | ||
ModelSingleton.metaGraph.addLinks(ModelSingleton.metaModel[PNLClasses.PROJECTION]); | ||
} | ||
|
||
static initInstance(initModel: any) { | ||
if (!ModelSingleton.instance) { | ||
ModelSingleton.instance = new ModelSingleton(initModel) | ||
} | ||
return ModelSingleton.instance; | ||
} | ||
|
||
static getInstance(): ModelSingleton { | ||
if (!ModelSingleton.instance) { | ||
throw Error("Model Singleton has not been initialised yet."); | ||
} | ||
return ModelSingleton.instance; | ||
} | ||
|
||
public updateModel(inputModel: any): ModelSingleton { | ||
ModelSingleton.instance = new ModelSingleton(inputModel); | ||
return ModelSingleton.instance; | ||
} | ||
|
||
public getModel(): Object { | ||
return ModelSingleton.model; | ||
} | ||
|
||
public getMetaModel(): any { | ||
return ModelSingleton.metaModel; | ||
} | ||
|
||
public getMetaGraph(): MetaGraph { | ||
return ModelSingleton.metaGraph; | ||
} | ||
|
||
public getComponentsMap(): ComponentsMap { | ||
return ModelSingleton.componentsMap; | ||
} | ||
|
||
public getInterpreter(): ModelInterpreter { | ||
return ModelSingleton.interpreter; | ||
} | ||
} |
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