Prefix System Variables with $

While the current_user is undoubtedly clear and concise, I think it could help to differentiate between system and user variables by prefixing system variables with a dollar sign, like this: $current_user or other data that is scoped globally, to the entire application.

In the future, I could even imagine exposing other variables that relate to underlying system functions. Some examples off the top of my head:

$beforeMount = function(app) => performSomeAppFunction()
$onNavigation = function(route) => performSomeRouteFunction(route)
$beforeDatabaseQuery = function(query) => performSomeRouteFunction(query);

A benefit of being able to hook into these systems as such is to allow for middleware to be created and take control before queries are executed, for instance. One could imagine placing these into a custom script that can be executed when the app is booting.

Needless to say, these methods would be considered advanced features, possibly activated through an Advanced option.

What do y'all think? I realize this suggestion may have exceeded the original topic, but expanding ideas are hard to control, am I right ? :wink:

Thanks! :wave:

1 Like

Begroeting Mark!

I agree it would be very helpful to better differentiate between global and page scoped variables.

A prefix might be the perfect fix :thinking:

I have seen several bugs where users are running into confusion related to what scoped level a variable/query/component is now that multipage apps has led to different tiers of accessibility :face_exhaling:

System functions would be super cool and useful, but might be a bit of a pandora's box. As Retool code executes in a sandbox, which leads to lots of interesting issues such as Javascript not being able to interact with the DOM/window or browser which unfortunately prevents mounting related logic :smiling_face_with_tear:

But onNavigation between pages in a multipage app for example or beforeQuery would be super cool and I would love to see those in Retool!

I agree these might need to be a feature that is enabled in advanced feature settings/options. I can make a feature request and keep you posted on anything i hear from the engineering team!

1 Like

I was thinking about that $ sign to indicate system variables. @Jack_T mentioned that it could differentiate between global and page scoped variables which is different.

I was wondering about this during my vacation. Might it not be easier to just add more information in the tooltip or add syntax highlights to these things?

I use this tooltip more often lately. I guess this can be extended with information on where it's being used / what it's dependencies are. And use syntax highlighting to differentiate between scoped vars, global vars and system vars?

Screenshot 2024-10-29 at 10.26.20

And yes, middleware could be useful. Especially when you want to reuse code and make it easy to use for others.

Hi @Steven_W,

Great feedback! I agree having more information in the tool tip would definitely help users as I see many running into scoping issues :sweat_smile:

Giving greater context to scoped vs global vs system vars would be a major help to developers and I can add this feedback on to the ticket I created.

Middleware is a bit more complex :melting_face: as users on cloud are running all their traffic through Retool servers, there might be another option for adding in a layer between the app's frontend and the Retool backend servers.

I believe that self-hosted users are able to add in a much higher level of customization in this department.

I use this tooltip more often lately. I guess this can be extended with information on where it's being used / what it's dependencies are. And use syntax highlighting to differentiate between scoped vars, global vars and system vars?

@Steven_W if you're interested in understanding how variables in your app are connected, you should check out this post and fill out this form!

The feature looks bit different than what is original shown there, but we're working on a way to visualize how apps are connected under the hood / make it easier for you to follow connections through your app.

1 Like