Skip to content

Commit

Permalink
console.log only if defined
Browse files Browse the repository at this point in the history
  • Loading branch information
mboinet committed Apr 30, 2013
1 parent db352f8 commit 5143c0c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/scripts/api.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

// API functions

define(['require','jquery','conf','router','models'],
function(require, $, conf, router, models){
define(['require','jquery','conf','router','models','utils'],
function(require, $, conf, router, models, utils){

// AJAX defaults
$.ajaxSetup({
Expand All @@ -29,12 +29,12 @@ define(['require','jquery','conf','router','models'],
" (" + jqXHR.statusText + ")");
} else {
// API errors go to the console
console.error('API error: ' + thrownError);
utils.log('API error: ' + thrownError);
}
} else {
// other states also go to the console too
console.error("API error with state " + state + ": " +
thrownError);
utils.log("API error with state " + state + ": " +
thrownError);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ requirejs.config({
requirejs(['jquery','backbone','conf','router','api','utils','models'],
function($, Backbone, conf, router, api, utils, models){


/************* utilities ***********/

function registerLoginPageActions(){
Expand Down
14 changes: 7 additions & 7 deletions src/scripts/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ define(['api','backbone','utils'],
window.localStorage.setItem(key, value);
}, this);
} else {
console.warn("Settings.sync called with unexpected method: " + method);
utils.log("Settings.sync called with unexpected method: " + method);
}

}, //sync
Expand Down Expand Up @@ -101,7 +101,7 @@ define(['api','backbone','utils'],
}, true);

} else {
console.log("CategoriesModel.sync method called for an " +
utils.log("CategoriesModel.sync method called for an " +
"unsupported method:" + method);
}
}
Expand Down Expand Up @@ -144,7 +144,7 @@ define(['api','backbone','utils'],
collection.trigger('sync');
}, true);
} else {
console.log("FeedsModel.sync called for an unsupported method: " + method);
utils.log("FeedsModel.sync called for an unsupported method: " + method);
}
}, // sync

Expand All @@ -166,7 +166,7 @@ define(['api','backbone','utils'],
function(m){

if (m.length == 0){
console.log("ArticleModel.sync: recived nothing for article " +
utils.log("ArticleModel.sync: recived nothing for article " +
model.id);
model.set("title", "Error");
model.set("content",
Expand All @@ -191,7 +191,7 @@ define(['api','backbone','utils'],

model.trigger("sync");
} else {
console.log("ArticleModel.sync called on an unsupported method: " + method);
utils.log("ArticleModel.sync called on an unsupported method: " + method);
}
},
toggle: function(what){
Expand All @@ -217,7 +217,7 @@ define(['api','backbone','utils'],
field: field },
function(m){ jQuery.noop(); } , true);
} else {
console.log("ArticleModel.toggle called with an " +
utils.log("ArticleModel.toggle called with an " +
"unexpected parameter : " + what);
}
}, // toggle
Expand Down Expand Up @@ -304,7 +304,7 @@ define(['api','backbone','utils'],
collection.trigger('sync');
}, true);
} else {
console.log("ArticlesModel.sync called for an unsupported method: " + method);
utils.log("ArticlesModel.sync called for an unsupported method: " + method);
}
}, // sync()

Expand Down
6 changes: 6 additions & 0 deletions src/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ define(['jquery'],function($){

return {

// log a message to the console if it exists else discard
log: function(m){
if (typeof console !== 'undefined'){
console.log(m);
}
},

// clean up a dom object (article to display)
cleanArticle: function(content, domain){
Expand Down

0 comments on commit 5143c0c

Please sign in to comment.