Skip to content

Commit

Permalink
Handle 404 xhr status on unavailable components of a cell
Browse files Browse the repository at this point in the history
  • Loading branch information
peterwmwong committed Oct 28, 2010
1 parent aa487d5 commit d226167
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 51 deletions.
13 changes: 6 additions & 7 deletions dist/current/cell-noRenderers.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ require.def('cell/util/loadComponents',
// Do not explicitly handle errors, those should be
// visible via console output in the browser.
if (xhr.readyState === 4) {
callback(xhr.responseText);
callback(xhr.responseText, (xhr.status === 404));
}
};
xhr.send(null);
Expand All @@ -426,8 +426,6 @@ require.def('cell/util/loadComponents',

if (!errors) {
cb(result, url);
} else {
ctx.errors.push(errors);
}

// Wait until all components are loaded
Expand All @@ -451,7 +449,8 @@ require.def('cell/util/loadComponents',
__resloader('template',_loadingCtx,loadTplCb);
__resloader('styling',_loadingCtx,loadStyleCb);
};
});require.def('cell/util/renderCSS',
});
require.def('cell/util/renderCSS',
[ 'cell/config' ],
function(config) {
return function(cname, styling){
Expand Down Expand Up @@ -592,11 +591,11 @@ require.def('cell/Cell',
console.log(err);
});

}else{
}
// Call Load Callback passing reference to Cell and errors
try{
if(typeof ctx.loadCb === 'function'){
ctx.loadCb();
ctx.loadCb(errors);
}
}catch(e){
console.log('cell.Cell.resumeLoad(): error thrown calling Load Callback for "'+this.name+'" Cell',e);
Expand Down Expand Up @@ -628,7 +627,7 @@ require.def('cell/Cell',

delete ctx.renderRequests;
}
}

};

return createClass({
Expand Down
13 changes: 6 additions & 7 deletions dist/current/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ require.def('cell/util/loadComponents',
// Do not explicitly handle errors, those should be
// visible via console output in the browser.
if (xhr.readyState === 4) {
callback(xhr.responseText);
callback(xhr.responseText, (xhr.status === 404));
}
};
xhr.send(null);
Expand All @@ -426,8 +426,6 @@ require.def('cell/util/loadComponents',

if (!errors) {
cb(result, url);
} else {
ctx.errors.push(errors);
}

// Wait until all components are loaded
Expand All @@ -451,7 +449,8 @@ require.def('cell/util/loadComponents',
__resloader('template',_loadingCtx,loadTplCb);
__resloader('styling',_loadingCtx,loadStyleCb);
};
});require.def('cell/util/renderCSS',
});
require.def('cell/util/renderCSS',
[ 'cell/config' ],
function(config) {
return function(cname, styling){
Expand Down Expand Up @@ -592,11 +591,11 @@ require.def('cell/Cell',
console.log(err);
});

}else{
}
// Call Load Callback passing reference to Cell and errors
try{
if(typeof ctx.loadCb === 'function'){
ctx.loadCb();
ctx.loadCb(errors);
}
}catch(e){
console.log('cell.Cell.resumeLoad(): error thrown calling Load Callback for "'+this.name+'" Cell',e);
Expand Down Expand Up @@ -628,7 +627,7 @@ require.def('cell/Cell',

delete ctx.renderRequests;
}
}

};

return createClass({
Expand Down
67 changes: 34 additions & 33 deletions src/cell/Cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,43 +49,44 @@ require.def('cell/Cell',
console.log(err);
});

}else{
// Call Load Callback passing reference to Cell and errors
try{
if(typeof ctx.loadCb === 'function'){
ctx.loadCb();
}
}catch(e){
console.log('cell.Cell.resumeLoad(): error thrown calling Load Callback for "'+this.name+'" Cell',e);
}

// Call Load Callback passing reference to Cell and errors
try{
if(typeof ctx.loadCb === 'function'){
ctx.loadCb(errors);
}
delete ctx.loadCb;
}catch(e){
console.log('cell.Cell.resumeLoad(): error thrown calling Load Callback for "'+this.name+'" Cell',e);
}
delete ctx.loadCb;

// Render template if there were requests while loading Cell
if(this.template){

// Render template if there were requests while loading Cell
if(this.template){

// Render styling
if(this.styling){
renderCSS(this.name, this.styling);
}

var _this = this;
ctx.renderRequests.forEach(function(req){
try{
__render(_this,
ctx,
req.domNodes,
req.replaceNodes,
req.data,
req.cb,
req.id);
}catch(e){
console.log('cell.Cell.resumeLoad(): error thrown rendering "'+this.name+'" Cell',req,e);
}
});

delete ctx.renderRequests;
// Render styling
if(this.styling){
renderCSS(this.name, this.styling);
}

var _this = this;
ctx.renderRequests.forEach(function(req){
try{
__render(_this,
ctx,
req.domNodes,
req.replaceNodes,
req.data,
req.cb,
req.id);
}catch(e){
console.log('cell.Cell.resumeLoad(): error thrown rendering "'+this.name+'" Cell',req,e);
}
});

delete ctx.renderRequests;
}

};

return createClass({
Expand Down
6 changes: 2 additions & 4 deletions src/cell/util/loadComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require.def('cell/util/loadComponents',
// Do not explicitly handle errors, those should be
// visible via console output in the browser.
if (xhr.readyState === 4) {
callback(xhr.responseText);
callback(xhr.responseText, (xhr.status === 404));
}
};
xhr.send(null);
Expand All @@ -42,8 +42,6 @@ require.def('cell/util/loadComponents',

if (!errors) {
cb(result, url);
} else {
ctx.errors.push(errors);
}

// Wait until all components are loaded
Expand All @@ -67,4 +65,4 @@ require.def('cell/util/loadComponents',
__resloader('template',_loadingCtx,loadTplCb);
__resloader('styling',_loadingCtx,loadStyleCb);
};
});
});

0 comments on commit d226167

Please sign in to comment.