Commit graph

22 commits

Author SHA1 Message Date
Matthijs Kooijman
c5314fe17a custom-module: Call reload() function on auto-reload
This allows modules to re-initialize any state they need whenever the
module is reloaded.

Without this, any such initialization can also be done in the top
level of the custom module, but this has two problems:

 1. Top-level module code runs on load and reload, and for the initial
    load, it runs *before* the connections are set up, so trying to use
    send() would produce an error on load (not reload).

 2. Top-level module code runs for the primary custom module, but also
    for any nested modules, removing control about the process and
    ordering from the primary custom module. In addition, a module that
    can be used both as primary and nested module, there is no clean way
    to distinguish between these cases.

Both of these problems can be solved by doing some bookkeeping in the
global object, but that produces messy code.

This commit allows modules to define a reload() function, which is
called (for the primary module only) after the module is reloaded. This
means that any initialization for the first load can be done in init()
and for reloads in reload(), and in both cases all connections will
already have been set up solving issue 1. In addition, neither of these
functions are called for nested modules, solving issue 2 (and the
primary module can then stil explicitly call a reload function on nested
modules if needed, as shown in the examples).
2024-06-18 09:37:01 +02:00
jean-emmanuel
b480889b70 custom module: add optional errorCallback argument toloadJSON and saveJSON 2023-04-05 22:57:50 +02:00
jean-emmanuel
81b6ca0557 custom module:don't restrict file extension in loadJSON() and saveJSON functions 2023-03-05 01:27:12 +01:00
jean-emmanuel
454884eb81 custom module: fix autoreload on nested submodules 2022-11-29 16:58:48 +01:00
jean-emmanuel
6ef1d412f9 custom module: expose global object that persists accross module reloads. 2022-11-29 08:36:09 +01:00
jean-emmanuel
ddcf186a66 custom module: prevent error when module.exports is not defined 2022-11-29 08:02:11 +01:00
jean-emmanuel
f896aa8d0c custom-module: clean 2022-05-22 12:24:46 +02:00
jean-emmanuel
0bdebc1357 custom module: proper submodule and circular require resolution 2022-05-22 12:13:53 +02:00
jean-emmanuel
0412ba2c28 custom-module: loadJSON: ignore BOM 2022-01-13 01:14:34 +01:00
bordun
81f503dc3d custom module: clearInterval() not working 2021-03-27 12:11:43 +01:00
bordun
1d6794e6af custom module: expose process global 2021-03-01 17:23:11 +01:00
jean-emmanuel
c056b986fd custom module: allow importing the main module without parsing it again 2021-02-22 12:40:46 +01:00
jean-emmanuel
ba2c25b998 custom module: prevent require() from reading submodules files each time and instead return the object in memory 2021-02-22 12:17:54 +01:00
bordun
b1ed680335 custom module: allow writing node apps (native require) 2020-12-14 06:59:56 +01:00
bordun
7316e85efb custom module: prevent reloading the module while the file is being written to 2020-11-21 18:47:34 +01:00
bordun
48c0440022 custom-module: attempt to bypass system file cache upon hot reload 2020-11-19 22:12:57 +01:00
bordun
94b1c6a5ee custom-module: document settings.appAddresses; restrict setting object access 2020-11-08 17:29:45 +01:00
bordun
3b269fafc4 custom-module: error log fix 2020-10-27 11:58:29 +01:00
bordun
2137c210bf custom-module: submodule autoreload fix 2020-10-27 11:55:34 +01:00
bordun
44b03941f9 custom-module: clean & docs 2020-10-27 10:30:09 +01:00
bordun
6cc020c10d custom module: add require() support 2020-10-27 10:17:59 +01:00
bordun
10dbd8c3c3 custom module: refactor custom module and add autoreload 2020-10-27 09:51:09 +01:00