Permalink
Browse files

Keep track of found sheets so we don't make endless requests when usi…

…ng the Backbone sync
  • Loading branch information...
1 parent c6e120b commit fdb1c3ee3bc0f7f3be6ab223a56f9f050fe32496 @jsoma committed Apr 4, 2013
Showing with 8 additions and 0 deletions.
  1. +6 −0 src/backbone.tabletopSync.js
  2. +2 −0 src/tabletop.js
@@ -39,6 +39,12 @@ Backbone.tabletopSync = function(method, model, options, error) {
if(typeof(sheet) === "undefined") {
// Hasn't been fetched yet, let's fetch!
+
+ // Let's make sure we aren't re-requesting a sheet that doesn't exist
+ if(typeof(instance.foundSheetNames) !== 'undefined' && _.indexOf(instance.foundSheetNames, tabletopOptions.sheet) === -1) {
+ throw("Can't seem to find sheet " + tabletopOptions.sheet);
+ }
+
instance.fetch( function() {
Backbone.tabletopSync(method, model, options, error);
})
View
@@ -213,8 +213,10 @@
loadSheets: function(data) {
var i, ilen;
var toInject = [];
+ this.foundSheetNames = [];
for(i = 0, ilen = data.feed.entry.length; i < ilen ; i++) {
+ this.foundSheetNames.push(data.feed.entry[i].title.$t);
// Only pull in desired sheets to reduce loading
if( this.isWanted(data.feed.entry[i].content.$t) ) {
var sheet_id = data.feed.entry[i].link[3].href.substr( data.feed.entry[i].link[3].href.length - 3, 3);

0 comments on commit fdb1c3e

Please sign in to comment.