refactor: remove dependency on search_strategy in fetch

This commit is contained in:
ROMAIN PHILIBERT 2015-05-21 03:53:15 -04:00
parent 05baf24ec9
commit 27c4d517ea
7 changed files with 14 additions and 27 deletions

View file

@ -13,6 +13,7 @@ define(function (require) {
var DocSource = Private(require('components/courier/data_source/doc_source'));
var SearchSource = Private(require('components/courier/data_source/search_source'));
var searchStrategy = Private(require('components/courier/fetch/strategy/search'));
var requestQueue = Private(require('components/courier/_request_queue'));
var errorHandlers = Private(require('components/courier/_error_handlers'));
@ -59,7 +60,7 @@ define(function (require) {
* individual errors are routed to their respective requests.
*/
self.fetch = function () {
fetch.searches().then(function () {
fetch.fetchQueued(searchStrategy).then(function () {
searchLooper.restart();
});
};

View file

@ -7,7 +7,7 @@ define(function (require) {
var errorHandlers = Private(require('components/courier/_error_handlers'));
var courierFetch = Private(require('components/courier/fetch/fetch'));
function SourceAbstract(initialState) {
function SourceAbstract(initialState, strategy) {
var self = this;
self._instanceid = _.uniqueId('data_source');
@ -38,7 +38,7 @@ define(function (require) {
});
self.history = [];
self._fetchStrategy = courierFetch.strategies[self._getType()];
self._fetchStrategy = strategy;
}
/*****

View file

@ -5,10 +5,11 @@ define(function (require) {
var sendToEs = Private(require('components/courier/data_source/_doc_send_to_es'));
var SourceAbstract = Private(require('components/courier/data_source/_abstract'));
var DocRequest = Private(require('components/courier/fetch/request/doc'));
var docStrategy = Private(require('components/courier/fetch/strategy/doc'));
_(DocSource).inherits(SourceAbstract);
function DocSource(initialState) {
DocSource.Super.call(this, initialState);
DocSource.Super.call(this, initialState, docStrategy);
}
DocSource.prototype.onUpdate = SourceAbstract.prototype.onResults;

View file

@ -5,10 +5,11 @@ define(function (require) {
var SourceAbstract = Private(require('components/courier/data_source/_abstract'));
var SearchRequest = Private(require('components/courier/fetch/request/search'));
var SegmentedRequest = Private(require('components/courier/fetch/request/segmented'));
var searchStrategy = Private(require('components/courier/fetch/strategy/search'));
_(SearchSource).inherits(SourceAbstract);
function SearchSource(initialState) {
SearchSource.Super.call(this, initialState);
SearchSource.Super.call(this, initialState, searchStrategy);
}
// expose a ready state for the route setup to read

View file

@ -2,11 +2,6 @@ define(function (require) {
return function fetchService(Private, Promise) {
var _ = require('lodash');
var strategies = this.strategies = {
doc: Private(require('components/courier/fetch/strategy/doc')),
search: Private(require('components/courier/fetch/strategy/search'))
};
var requestQueue = Private(require('components/courier/_request_queue'));
var fetchThese = Private(require('components/courier/fetch/_fetch_these'));
@ -19,21 +14,9 @@ define(function (require) {
else return fetchThese(requests);
}
/**
* Fetch all pending docs that are ready to be fetched
* @async
*/
this.docs = _.partial(fetchQueued, strategies.doc);
/**
* Fetch all pending search requests
* @async
*/
this.searches = _.partial(fetchQueued, strategies.search);
this.fetchQueued = fetchQueued;
function fetchASource(source, strategy) {
strategy = strategy || strategies[source._getType()];
var defer = Promise.defer();
fetchThese([
@ -89,4 +72,4 @@ define(function (require) {
});
};
};
});
});

View file

@ -2,15 +2,16 @@ define(function (require) {
return function DocLooperService(Private) {
var fetch = Private(require('components/courier/fetch/fetch'));
var Looper = Private(require('components/courier/looper/_looper'));
var docStrategy = Private(require('components/courier/fetch/strategy/doc'));
/**
* The Looper which will manage the doc fetch interval
* @type {Looper}
*/
var docLooper = new Looper(1500, function () {
fetch.docs();
fetch.fetchQueued(docStrategy);
});
return docLooper;
};
});
});

View file

@ -23,4 +23,4 @@ define(function (require) {
return searchLooper;
};
});
});