How can I define and access global variables in an Incisor project?
In a typical Incisor project, the code is split across multiple packages and files. There will be situations where it's necessary to reference data that needs to be globally accessible. What is the best way to create and access global variables throughout the codebase?
How can I define and access global variables in an Incisor project?
In a typical Incisor project, the code is split across multiple packages and files. There will be situations where it's necessary to reference data that needs to be globally accessible. What is the best way to create and access global variables throughout the codebase?
Share Improve this question asked Feb 14 at 17:34 Matt CMatt C 853 bronze badges1 Answer
Reset to default 0In an Incisor project, you can create global variables by adding them to the pr
reference, which points to the ProjectMain
object. As long as your classes are instantiated and used within the ProjectMain.init()
flow (which is required for the project to function properly), these variables will be accessible throughout the project.
For example, to create a global variable, you can add it directly to the pr
object or the ProjectMain
class:
class ProjectMain {
init() {
this.myGlobalVar = "Accessible globally as 'pr.myGlobalVar'";
}
}
This way, myGlobalVar
will be available anywhere in the project, as long as the `pr object is in scope.