Closed gamtiq closed 10 years ago
Hey @gamtiq. What sort of use cases do you have in mind, or maybe you've seen for defined
? It sounds interesting, but I'm having trouble figuring out how/when I would want to use it. Thanks!
Hello Brian,
Maybe the main reason is for compatibility purposes (at least at the moment).
For example, it would help to develop AMD plugins that are compatible with curl
and RequireJS
.
When I was adapting my view plugin to RequireJS
I found this method and it helped me to make the adaptation easier.
Of course, these arguments are very subjective.
Hey guys,
Just reading through view.js. I don't really understand what this line is doing. It seems to be checking the cache and/or mapping to the module's path.
Sorry, I'm just trying to figure out what the use case is so I can offer a suggestion. :)
-- John
Hello John,
The test in the line was added to detect and adapt to RequireJS because in RequireJS version of toUrl
function returns different value than version of curl.
Thanks, Denis
Hey @gamtiq,
I was just looking at your code, and it seems to me that it would be a lot simpler if conf.parse() returned an array of inclusion objects rather than a hashmap-object and an array. Then you could link the parse results with the resources via the arguments: resource = arguments[i + 1];
where i
is the index into the inclusion array.
I don't think this case is compelling enough to put a require.defined(id) API into curl.js, at the moment. I don't think James should have added that to RequireJS. Synchronous determination of a module's status seems like a pitfall for newbs, and is only needed by a few advanced devs such as you.
Here's how you find out if a module is defined in curl.js:
// this should be scoped so that `require` is any local require
var isDefined = (function (cache) {
return function (id) { return id in cache; };
}(require('curl/_privileged').cache));
I hope that helps! Reopen this if not.
-- John
Hello John,
Thank you for your opinions and suggestions! I must agree that this method is not absolutely necessary. So I close this issue.
Thanks, Denis
RequireJS has "defined" method that allows checking whether "the module has already been loaded and defined" (see here). The method is attached to global and local
require
. It would be useful to have the same method incurl
.