Variables in Apps and Browser Plugins


John Clarke
I have a couple of questions regarding using variables within applications and browser plugins. These are as follows :

Applications

1.If I want a variable that is Global for the whole application (one that I can reference on all views) where do I define it ?
2.If I want a variable that is Global for the view only where do I define it ?

Browser Plugins

1. When I use the WebExtMessage and WebExtContent and I want to update variable values for the view do I have to do the following :

a. Set the variables using chrome.storage.local.set
b. On the view show event get them using app.getOption

Or can I directly access the variables set on the view of the plugin?


DecSoft

Hello John,

Please, take a look at the "app.setVar()" method help, which can establish "global reactive variables" and also told you about this "reactive" variables and the ability to use just "global variables" using the "window" one as the parent for it.

There is no variables "only for views", however, it's possible to establish it if we wanted and in two possible ways. Supose we are talking about the "Show" event of an app view, then, we can define a variable like the below one:

Declaring a variable like the above, means that that variable is available only for the app view Show event, and, not out of that event. But, taking the example of the "non reactive global variables" (as you can see in the above link), we can think in the declaration of variables like below:

Doing that, what you get is a variable placed in a specific container, to say like that, so, you can know that that variable refers to some specific app "myView" variables. So there is not something "out of the box", but, we have the freedom to establish variables in "containers" like the above, who can provide some context for that variables.

About the variables defined in the app and the variables defined in the context of a a Web Extension, we must remember that that contexts are completely separated, so, we can't define app variables to be accessed from the context of the Web Extension and viceversa. This applies also to the local storage: if I am not wrong, the local storage that we can use in the Web Extension context are not the same than the app local storage.

Fortunately we can pass messages from the Web Extension context and the app context and viceversa, so, it's possible to send a message to the app which inform to the app that must save some value in certain app local storage using the "app.setOption" method, for example. So what we must take in consideration is that the contexts are different, and we can't directly accesss the contexts in a "direct way", but, using the communication / messages mechanism.

Please, go ahead and post here if you have some doubts or any further questions around these points.


Todo el mundo puede leer el foro de soporte de DecSoft para aprender del mismo, sin embargo, sólo los clientes de DecSoft pueden abrir nuevos hilos. Compre una o más licencias de productos de DecSoft y obtendrá este y otros beneficios.

Este sitio utiliza "cookies" útiles para almacenar sus preferencias.

Bien. Ocultar esta nota. Obtener más información.