Ticket #2529742 (closed enhancement)

Reporter


Michael Hasenstein
Opened: 01/5/11
Last modified: 08/1/12
Status: closed
Type: enhancement
Resolution: fixed

Owner


Dav Glass
Target Release: 3.6.0
Priority: P3 (normal)
Summary: Y[UI()].use() callback's 2nd parameter: 2 issues
Description:

When performing a Y.use(modules, callback) the callback gets TWO parameters: The YUI instance, AND a response object from the loader.

Issues:

- That 2nd parameter is not documented.

- The response is "success" when I try to load a module that the loader does not know about:

Y.use('no-such-module', function (Y, result) {console.dir(result);})

Hoowever, when I have a group-configuration for my own modules and try to load a non-existing module matching that group's pattern the loader goes out and trys to load it, and in this case I DO get
an error response.

In general, I think having the response object is MOST helpful. I know in the YUI-configuration I can specify onsuccess and onfailure handlers, but the disadvantage of them is they are global and I
would like to know about failures locally. I could set locally-aware functions before each use of Y.use(), but that's a lot of work compared to simply using the response status inside the callback
function. If one loads all modules upfront the global handlers are fine, but when one has a lot of loading going on on demand locally in many places in the code it would be so nice to just use that
response object.

So I would like to vote for making it "offical" by adding it to the documentation, and for making it work consistently (returning an error in the above example where there is no XHR call going on
because the loader decides right away there is no such module).

Type: enhancement Observed in Version: development master
Component: YUI Global Object Severity: S3 (normal)
Assigned To: Dav Glass Target Release: 3.6.0
Location: Library Code Priority: P3 (normal)
Tags: Relates To:
Browsers: N/A
URL:
Test Information:

Change History

Michael Hasenstein

Posted: 01/5/11

I just found that when I do the same (definitely failing) call twice I get different results (and both are wrong as stated above):

CODE: Y.use('no-such-module', function (Y, result) {console.dir(result);})

RESULT 1: {data:["no-such-module"], msg:"success", success:true}
RESULT 2: {success:true}

Michael Hasenstein

Posted: 01/5/11

One more update:

When I force the loader to try to load a module (by specifying a group and a pattern for it, and using a module name matching that pattern, so that the loader cannot decide if it's a valid module without trying to load it from the server) I get a (correct) error (success:false) in the response.

However, when I perform the call a second time I also get {success:true}, so it seems if there is a cache hit one always gets the same response.

Adam Moore

YUI Contributor

Posted: 01/5/11
  • milestone changed to FUTURE
  • priority changed to P3 (normal)
  • status changed from new to accepted

'no-such-module' is a dev-time problem. Use the -debug version of the seed file during development and the console log will let you know you have a problem. Missing modules are currently messaged even when you use the -min file. Success is reported because these mistakes are normally typos, and YUI will attach what it can and try to continue -- I'll look at this part.

Regarding the error response you saw with pattern matched modules, you must be using firefox -- other browsers will report success even though there was a 404 error, or they will just hang until a timeout if defined. This is a general problem with script loading that I'm in the process of making easier to deal with.

Michael Hasenstein

Posted: 01/5/11

> 'no-such-module' is a dev-time problem

I beg to differ - slightly :-) You're thinking of "closed" apps.

I have generic application code which depending on the URL of the link clicked loads a module with the appropriate name. If the link is /items/12 it loads "mysite-items", etc. So on the one hand yes, that COULD be considered dev. issue - but not if I don't control everything, all modules, all links and all pages. I would like to be able to live with an error introduced by one of many people or entities, for which no one would be personally responsible, it just happens that there's a link that SHOULD lead to loading the appropriate module, but there is no module. You guys make sure everything in YUI is sooo generic, modular, ready for distributed modular apps - living with fallability is one aspect.

Background: I have written (based on Dav Glass's work) a site that works with or without Javascript, all rendering is done on the server by node.js if necessary. Also, if there IS Javascript, I don't let the browser change the page - only the homepage is loaded and ALL links are intercepted, a URL which normally is /items/12 is translated to /#/items/12, so that my client side app keeps the original real URL (path) in the hash and history and bookmarks work. For any clicks on links that client side code loads a module "mysite-firstPartOfLink" (example as above) and let's it render into the content container of the page. It works! But I don't see how I can check in advance that every link will always have the appropriate module. Or, better, why I even should. Sure it's an error, but with the same argument you could say 404/Not Found pages are unnecessary because they should never happen. What if a user enters a link manually and mistypes it? What if a bookmarked link is no longer valid and now leads to the attempt to load a module that no longer exists? Anyway, this way the website's CSS and JS are loaded *and parsed* by the browser only ONCE in addition to all the other niceties of having the same code on client and server and of having it work with or without client-side JS. It works! Okay, that's not quite a necessary part of the bug report, just some background.

George

YUI Developer

Posted: 04/20/11

Dav Glass

Posted: 04/26/11
  • location changed to Library Code
  • status changed from assigned to accepted

Dav Glass

Posted: 03/30/12
  • milestone changed from FUTURE to 3.6.0

Dav Glass

Posted: 04/5/12
  • estimated changed from 0 to 0.25
  • remaining changed from 0 to 0.25
  • sprint changed to sprint 1

Dav Glass

Posted: 05/21/12
  • completed changed from 0 to 0.25
  • remaining changed from 0.25 to 0
  • sprint changed from sprint 1 to sprint 2

Dav Glass

Posted: 05/21/12
  • resolution changed to fixed
  • status changed from accepted to checkedin

Fixes #2529742 - Better messaging in status object of use callback
View Commit: 75aad08cf19d9c79452baef05e450d79e3a0c847

Jenny Donnelly

YUI Developer

Posted: 08/1/12
  • status changed from checkedin to closed

Shipped in 3.6.0. Marking closed/fixed.