You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • Tried in console the following... according to Modules reference:

    >reset()
    =undefined
     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v92 Copyright 2016 G.Williams
    >Modules.removeAllCached();
    =undefined
    >Modules.getCached()
    =[  ]
    >Modules.addCached("credsTest",'{ssid: "ssidVal"}');
    =undefined
    Uncaught SyntaxError: Got ':' expected EOF
     at line 1 col 8
    {ssid: "ssidVal"}
         ^
    >Modules.addCached("credsTest",'{"ssid":­ "ssidVal"}');
    =undefined
    Uncaught SyntaxError: Got ':' expected EOF
     at line 1 col 8
    {"ssid": "ssidVal"}
           ^
    > 
    

    Both - non-JSON and JSON - ways fail... I suspect that the new feature to load modules as a function meddles with the previous workings... may be the issue is with both, upload AND pull ( require("..."); )...

    @Gordon, could it be that the feature of saving modules as functions is doing things differently?

    *** BUT*** *** BUT*** *** BUT*** *** BUT*** *** BUT***

    Doing it in a module:

    // credsTest.js
    exports = { ssid: "ssidVal", pw: "pwValue" };
    

    ...and in the code as follows:

    // credsObjTest.js
    var creds = require("credsTest");
    function onInit() {
      console.log("creds object:");
      console.log(creds);
      console.log("Modules as loaded:");
      console.log(Modules.getCached());
    }
    // for the laxy developer at development time:
    setTimeout(onInit,1000);
    

    ...I get this output on upload:

    >
     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v92 Copyright 2016 G.Williams
    >
    =undefined
    creds object:
    {
      "ssid": "ssidVal",
      "pw": "pwValue"
     }
    Modules as loaded:
    [
      "credsTest"
     ]
    > 
    

    The last line is only that I do not have to enter onInit() in the console. Saving the code without the last line on my PICO I get following output (...because save() invokes onInit() and I'm still connected):

    >save()
    =undefined
    Erasing Flash.....
    Writing.....
    Compressed 81600 bytes to 3066
    Checking...
    Done!
    Running onInit()...
    creds object:
    {
      "ssid": "ssidVal",
      "pw": "pwValue"
     }
    Modules as loaded:
    [
      "credsTest"
     ]
    > 
    

    @ClearMemory041063, I do not know what it fighting you...

    @Gordon, made another try in the console with (modules source code and not just source code):

    >reset()
    =undefined
     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v92 Copyright 2016 G.Williams
    >Modules.removeAllCached();
    =undefined
    >Modules.getCached();
    =[  ]
    >Modules.addCached("credsTest",'exports = {ssid: "ssidVal"};');
    =undefined
    >Modules.getCached();
    =[
      "credsTest"
     ]
    >require("credsTest");
    ={
      "ssid": "ssidVal"
     }
    > 
    

    And it works, works, works,... nothing is broken... (so: @Gordon, never mind my comments from before...)

About

Avatar for allObjects @allObjects started