Question about require() #513
Replies: 9 comments
-
Posted at 2015-10-22 by @gfwilliams It depends on whether you're using the Web IDE to load modules, or have them on an SD card.
In both cases, the |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-22 by sameh.hady I am using the Web IDE, so that means that the Web IDE will grab all required modules first and will just discard which function is calling it. I guess this wont change anything then and my big function will be loaded whenever I call my module |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-22 by @gfwilliams Yes, absolutely. Potentially a module is slightly worse as nothing in it can get freed in case the module is used again. If you did something like:
you could explicitly remove the function. You could actually do |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-02 by seriousStuff hi, i created a simple wrapper for the 'HC-SR04' which abstracts the low level handling. when i 'require(...)' this file i get the error message that the modul can not be found. it seems to me that it is not possible for a module (from the modules directory) to require another module regardless if it's a local one or from the web? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-03 by @gfwilliams Ahh. I'll have a look at this today, it may have come up before. It could well be a bug in the module handling that happens for the 'projects' code in the Web IDE. For now, I guess you could just pass it in:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-03 by @gfwilliams Looking at this now - seems everything is working but there's an issue with the ordering of module initialisation. Easiest solution for now is to just do:
... Or, I guess you're doing something like this in your module:
But if you did this, it'd all work:
... just to add, I don't think there's anything different with the projects code at all - all modules are handled the same right now. It's just that if modules use other modules, they're generally written not to use them in the global scope. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-03 by @gfwilliams Ok, just fixed this - but it won't update until I push the next version of the Web IDE I'm afraid. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-09 by seriousStuff Hi, thank you for looking into this! Will test this out, the intermediate solution above is fine! Thanks for doing an amazing job! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-09 by @gfwilliams I'm not sure - I might try and do a release next week? I like to try and use it quite a bit here first, just in case any bugs got introduced :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2015-10-22 by sameh.hady
I have a question, lets say i have a big function called bigFunction() that is being called inside Testing module in connect() function. If I packaged this function as a module and called it something like bigFunction and instead of calling this function from my Testing module I do a require("bigFunction").
When will the require do its job and grab the file? when i require the Testing module or when I call the function that requires it?
require("Testing") <--- Will it be loaded here?
require("Testing").connect() <--- includes require("bigFunction") or only here?
What I want is to only grab the big function if I required it to save space and memory
Beta Was this translation helpful? Give feedback.
All reactions