Okay, that's basically what I recalled and fills in the blank on why it was done.philo wrote: ↑Tue Mar 01, 2022 8:26 amThis was designed deliberately. Global variables are a pain and lead to bad programming practices and code that is hard to maintain / understand.
- Spoiler: show
The purpose of the scriptvar object is to hold state between pages.
Global javascript was meant to be used for reusable functions, it was never designed to be used to hold state.
There was a bug where that was not cleared down in some circumstances, but was inconsistent, so setting a global variable worked by accident some of the time, that was fixed
- Spoiler: show
While I agree that global variables are not necessarily the best practice, the fact remains that they are valid javascript, and they do get used. I agree with RemiHiyama that scriptVars seem to just betaking the place of global variables, but the main difference is it forces them to be explicit, and communicates to GuideMe what needs to be saved in the guide state between sessions. Come to think of it, if javascript required explicit globals some of my issues would be greatly reduced.
So (and correct me if I'm wrong) it seems the source of the issue is that EOS and Guideme use slightly different models and assumptions.
In Guideme it's assumed that all pages are essentially independent and scriptVars() are used to share information between pages, while at the same time keeping Guideme informed of what needs to be saved between sessions, and saving of the session state is done automatically.
In EOS it's assumed that pages are all related, and global variables hold the state while a session is active, and allow shared data between pages, then the teaseStorage() module is used to explicitly save selected variables between sessions, and this must be explicitly done by the programmer.
So in summary:
Guideme requires manual communication between pages, but provides automatic saving of the state between sessions.
EOS = provides automatic communication between pages, but requires manual saving of the state between sessions.
I'll sleep on it a bunch more times and see what other ideas come up, and what happens when I start re-writing the affected portion of my downloader. I guess it may just never be perfect, but if I just take it one issue, and one step at a time it will continue to get better.
Thanks for the replies guys!
PG