Adds resourceFilter option

This commit is contained in:
zVictor
2014-08-18 16:16:23 +02:00
parent e2f0806105
commit 67c106cc10
4 changed files with 130 additions and 74 deletions
+9 -6
View File
@@ -48,12 +48,10 @@ function ResourceManager(options) {
*/
function fetchResources(useCache, currentView) {
var cache;
// if useCache is not defined, default to true
useCache = (typeof useCache !== 'undefined' ? useCache : true);
if (cache !== undefined && useCache) {
// get from cache
return cache;
} else {
if (!useCache || cache === undefined) {
// do a fetch resource from source, rebuild cache
cache = [];
var len = resourceSources.length;
@@ -61,8 +59,13 @@ function ResourceManager(options) {
var resources = fetchResourceSource(resourceSources[i], currentView);
cache = cache.concat(resources);
}
return cache;
}
if($.isFunction(options.resourceFilter)) {
return $.grep(cache, options.resourceFilter);
}
return cache;
}
/**
@@ -131,4 +134,4 @@ function ResourceManager(options) {
normalizers[i](source);
}
}
}
}