• Hi,

    I've hit a few things recently where it's been a bit annoying to run code on initialisation. For instance say you have two bits of code:

    A

    function onInit() {
      require("my_lcd").connect(...., drawStuff);
    }
    
    function drawStuff() {
    }
    

    B

    function onInit() {
      require("my_wifi").connect(...., function() {
       requestStuff();
      });
    }
    
    function requestStuff() {
    }
    

    You can't just copy and paste those bits of code - if you do the second onInit will overwrite the first silently and only the second will get executed. You've got to merge the two onInit.

    So to me, a good solution would be to have a init event - just like you have for Serial1.on('data', ...);

    Any thoughts about what the event should come from? I guess one thought is the global object - so you could do:

    global.on('init', function() {
      require("my_lcd").connect(...., drawStuff);
    });
    

    Or I could put it on the E object, like:

    E.on('init', function() {
      require("my_lcd").connect(...., drawStuff);
    });
    

    Any preferences? I guess for me, E is edging out, because it's nice and short :)

About

Avatar for Gordon @Gordon started