I am new to TypeScript and object oriented programming, I have some functions that should wait for each other (promises in JavaScript) and promises are depending on each other, for example:
In the main script file, I have the main class, and I imported other files and classed inside it. (I mean using import {bla-bla-class} from "bla-bla"
)
I had a promise
for load
(depending on the page and internet speed may take some milliseconds or seconds...) using addEventListener
and configSetter
method is awaited
for that method (load
) to set the configs (I needed the page be completely loaded for setting the configs), then I needed to tell ready()
method in my main
class that the page is loaded and configs set correctly, because of this I added another promise
for ready()
method inside the main
class to wait for configSetter()
method (because the config setter itself needed to wait for load
method, ready()
was also depending on it, so I need to wait), when I compiled and bundled files, the file was heavier than what I was expecting, and also my TypeScript files was more complicated to understand because of differents promises
I used
I thought maybe I can export the main
class and also make its ready()
method static
, so I could access my main class's ready()
method from another class easily, but now I am not sure, if is this something that people do in object oriented programming?
Is it okay to use the main class's methods (even as static) inside other classes and methods? (specially when they are not main classes and are just some helpful methods... should they be able to call the main
class methods?)