Skip to content

Commit

Permalink
Added core functionality, including interceptor. WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
atruskie committed Dec 18, 2014
1 parent 6679eb3 commit d52bea6
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 106 deletions.
40 changes: 36 additions & 4 deletions src/components/services/predictiveCache.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
angular
.module("bawApp.services.predictiveCache", [])
.factory(
"predictiveCacheInterceptor",
[
function () {
var _listeners = [];
return {
listeners: function() {
return _listeners;
},
request: function pciRequest(httpConfig) {

_listeners.forEach(function)

return httpConfig;
}
/*
requestError: ,
response: ,
responseError:
*/
};
}
])
.factory(
"predictiveCache",
["$http", function ($http) {
["$http", "predictiveCacheInterceptor", function ($http, predictiveCacheInterceptor) {

var defaults = {
name: null,
Expand All @@ -16,6 +39,8 @@ angular
var defaultProgression = 1;
var unnamedProfiles = 0;

var profiles = {};

function validateProfile(settings) {
settings = angular.extend({}, defaults, settings);

Expand Down Expand Up @@ -63,7 +88,7 @@ angular
throw new Error("progression must be an array of numbers/functions");
}

if(!angular.isNumber(settings.count) || settings.count < 0) {
if (!angular.isNumber(settings.count) || settings.count < 0) {
throw new Error("count must be a positive integer");
}

Expand All @@ -74,14 +99,21 @@ angular
return settings;
}

function createInterceptor() {
};

return function predictiveCache(profile) {
if (!angular.isObject(profile)) {
throw new Error("A profile is required");
}

var settings = validateProfile(profile);

profiles[settings.name] = settings;

return settings;
};
}]
);
}])
.config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push("predictiveCacheInterceptor");
}]);
Loading

0 comments on commit d52bea6

Please sign in to comment.