Open ademenev opened 5 months ago
I gave it a look.
It's very easy watch, e.g., all Python files that are located in the same directory as the sketch file. The actual reloading is trickier. You could, e.g., blanket eval all of these files, but this can lead to unwanted (even bad) side effects. For example one may have a "cleanup" (or otherwise filesystem interacting) script in that's only meant to be executed manually. It would be ok to trigger a redraw when such a script is modified, but it would not be ok to actually execute it by mistake.
Ideally, we should extract from the sketch script the actual dependencies, and only watch/reload them. It's not immediately obvious to me how to proceed exactly.
Alternatively, we could add some optional API to the sketch class, like a list of additional files to watch/reload, or a flag to opt-in to watch/reload all python files in the same directory.
For small projects it is OK to have all code in one file, but oftentimes my projects are big and should be better split into multiple files. Even though that works, the imported module files are read only once, and not reloaded on code change