Hello there,
Sorry for the long text ;P
We use requirejs for module loading, therefore we might end
with each module having it's own doc.ready trigger. No biggie as
jQuery pile up the callbacks in an array and do a for(). Using
requirejs means async loading and then, the ready callbacks are queued
at different order.
- var
logger = '#log';
-
- //file1
- $(function(){
-
$('<li/>').text('ready 1').appendTo(logger);
- });
- //file2
- $(function(){
-
$('<li/>').text('ready 2').appendTo(logger);
- });
- //file3
- $(function(){
-
$('<li/>').text('ready 3').appendTo(logger);
- });
- //file4
- $(function(){
-
$('<li/>').text('ready 4').appendTo(logger);
- });
- //file5
- $(function(){
-
$('<li/>').text('ready 5').appendTo(logger);
- });
On fire(), list will be an array with 5 functions. Each will be
called by list[
firingIndex ].
apply
(
data[
0
], data[
1
] ).
So, the issue was that one of the callbacks on one of the modules
of another team was wrong and had a TypeError. So the callback for
some of the ready() were never been called.
- var
logger = '#log';
-
- //file1
- $(function(){
-
$('<li/>').text('ready 1').appendTo(logger);
- });
- //file2
- $(function(){
-
$('<li/>').text('ready 2').appendTo(logger);
- });
- //file3
- $(function(){
-
$('<li/>').text('ready 3').
typeErrorFn(logger);
- });
- //file4
- $(function(){
-
$('<li/>').text('ready 4').appendTo(logger);
- });
- //file5
- $(function(){
-
$('<li/>').text('ready 5').appendTo(logger);
- });
Now the title's question:
Could jQuery.Callbacks fire() play safer when calling up the
stacked callbacks?
I mean, could list[
firingIndex ].
apply
(
data[
0
], data[
1
] ) be wrapped on a try/catch, where catch pushes any errors
to an errorArray and in the end of the for() then the errors are
thrown or console.logged? That is, can jQuery's fire() be
decoupled of third-party code errors (a.k.a. us who use jQ) in order
to not halt jQuery's own execution of callbacks?
Thinking on different .js files/code blocks, inside their own
closure one does not halt another execution (if they are unrelated or
don't call one another). But in this case where all come into
jQuery's fire(), one error halts all jQ execution.
I guess was explained okay. But if not, let me know, I'll
gladly explain better any part of the idea.
Regards,
Raphael
PS: Yes, would be best just fix the typeError, but sometimes the
module/code is from another team so you can't much fix it by
yourself, you gotta report and etc. Bureaucracy, you know. But the
main point here is jQ flow breaking 'cause of bad callback.