• Looks good - I'd say if you're running into out of memory errors, you should probably just do what is described in the first step - without using Modules.addCached.

    Pulling modules over the internet is very possible - it's actually quite easy (download as a string, and use Modules.addCached). The problem is that it needs to be asynchronous, and require is synchronous - so it can't be built in as part of the standard require function.

    For replacing a module, you'd have to have a carefully designed module that could fully unload itself - and that you kept no references to. However if that is done then yes, replacing it on the fly could definitely be done.

  • The problem is that it needs to be asynchronous, and require is synchronous

    ...with that comment we come full circle with #4 and #5 of the conversation about How to create a module that is a 'Class' - aka a function usable with new - or: How to make require() return a function and not an object.

    A nice historical event...

    At that time you posted '...That one's definitely not in my plans at all I'm afraid!'. With promises now implemented, I'm not so sure this statement of your's still stands firm... ;-) ---

    *** Espruino is now closer to the require.js / AMD as it ever was... and kind of an M2M Browser Eco System vs. a Web Browser... ***

    (Just a little bit food for thought: enabling require to detect the invocation pattern/method signature - single string vs. array - would allow the async approach, of course it also requires some flanking support actions, like a way to define how and where to pull the modules asynchronously. This food for thought is though a rabbit trail of this conversation and will have to be in its own conversation).


Avatar for Gordon @Gordon started