• For educational 'playing' while connected and without saving, things work just fine.

    For modules that connect to devices with dynamic, volatile configurations, save does - and cannot - save the state of the device, because it lives only inside the device and the device doe not have a save and restore function... and even if they would have, Espruino's save() would have to know about it and also know about how to call the particular device's save...

    Separating the Espruino related initializations from initializations of the connected devices is the key to the solution. It is obvious that build-time oriented things - 'require' - and runtime oriented things - 'connect' - need to be separated - and can therefore not exist in the same statement. Choosing the approach of crating a module reference and use the module reference later in the code is not a viable approach.

    Having the code structured with getting the resources first and apply basic (static) initialization and then issue a save() is the way to go. The onInit() and E.on('init') have to happen afterwards. Observing this pattern of code structure and process timing creates restartable applications.

About

Avatar for allObjects @allObjects started