celest-dev / celest

The Flutter cloud platform
https://celest.dev
Other
232 stars 13 forks source link

Knowing when some function is used in frontend/backend code. #57

Open marcglasberg opened 4 months ago

marcglasberg commented 4 months ago

When I have some function that's used in both the frontend and the backend, it may need to know if it's running in the client (my_app/lib/) or in the Celest dir (my_app/celest/).

Just knowing this fact is important, but it also helps me to choose between using celest or celestBackend when I want to check the CelestEnvironment.

String whereAmI() {
     if (celest.running == CelestRunning.clientCode) {
        if (celest.currentEnvironment == CelestEnvironment.local) return "Client code, local";
        if (celest.currentEnvironment == CelestEnvironment.production)  return "Client code, prod";
     }   
     else if (celest.running == CelestRunning.serverCode) {
        if (celestBackend.currentEnvironment == CelestEnvironment.local) return "Celest code, local";
        if (celestBackend.currentEnvironment == CelestEnvironment.production)  return "Celest code, prod";
     }
}
dnys1 commented 4 months ago

Interesting use case! Hmm.. I will need to give this one some thought.

dnys1 commented 4 months ago

@marcglasberg One trick you could do right now is check if you're running in Flutter:

const runningInFlutter = bool.fromEnvironment('dart.library.ui');
marcglasberg commented 4 months ago

Nice trick!