know-cujojs / know

Know cujoJS through these short, focused tutorials
Other
5 stars 5 forks source link

Tutorial: Consuming modules: Module ids #13

Open teehemkay opened 11 years ago

teehemkay commented 11 years ago

I think that one ../ is missing below:

// module app/billing/billTo/Customer
define(function (require) {
    [...]
    // BAD: normalizes to "../util/date" -- a URL, not an ID!
    var Date = require("../../../util/Date");

Should probably read:

// BAD: normalizes to "../util/date" -- a URL, not an ID!
var Date = require("../../../../util/Date");

Also congrats on a really awesome tutorial!

briancavalier commented 10 years ago

Hey @exidia, thanks, I think you're right. I think the intent was to show a module id that tries to back out "too far"--that is, beyond even the conceptual / (baseUrl). Three double dots backs out exactly to /, which would normalize to the valid id util/Date. So, four .. seems like it does what the comment says.

I definitely want @unscriptable have a look to verify, though.

teehemkay commented 10 years ago

Hi Brian, thanks for your comment. That was my reasoning too.

And there's actually an example in the next tutorial, "Consuming modules: Locating modules in AMD" at http://know.cujojs.com/tutorials/modules/consuming-locating-modules-in-amd, under the chapter "Why multiple ../ is a code smell" that provides an explanation similar to the one you gave above.

Oh and BTW, I think that the tutorials are really, really great: very clear and to the point, concise and very well balanced in terms of providing the right amount of details at both practical and conceptual levels.

briancavalier commented 10 years ago

And there's actually an example in the next tutorial

Nice, I think that confirms it. I just sent #14 as a fix.

concise and very well balanced in terms of providing the right amount of details at both practical and conceptual levels.

Thanks! We appreciate the feedback. Finding that balance can be tough, so knowing that we've gotten it right so far definitely will help us when writing more tutorials.