Revert "prevent multiple autopage requests, fix #201"

This reverts commit 67daf10747.
This commit is contained in:
Bernhard Posselt 2013-12-20 17:30:51 +01:00
Родитель 67daf10747
Коммит 0454021bc3
6 изменённых файлов: 5 добавлений и 71 удалений

Просмотреть файл

@ -27,11 +27,9 @@ angular.module('News').factory '_BusinessLayer', ->
constructor: (@_activeFeed, @_persistence, @_itemModel, @_type,
@_$rootScope) ->
@_preventAutopage = false
load: (id) ->
@_preventAutopage = false
@_$rootScope.$broadcast 'loadingNewItems'
@_itemModel.clear()
@_persistence.getItems @_type, id, 0, =>

Просмотреть файл

@ -106,7 +106,6 @@ StarredBusinessLayer, NewestItem) ->
loadNext: (callback) ->
lowestItemId = @_itemModel.getLowestId()
if lowestItemId != 0
@_persistence.getItems @_activeFeed.getType(),

Просмотреть файл

@ -30,7 +30,7 @@ $rootScope, $q) ->
constructor: (@_request, @_feedLoading, @_autoPageLoading, @_newLoading,
@_config, @_activeFeed, @_$rootScope) ->
@_preventUselessAutoPageRequest = false
init: ->
###
@ -64,16 +64,13 @@ $rootScope, $q) ->
# show different loading signs
if offset == 0
@_preventUselessAutoPageRequest = false
loading = @_feedLoading
else
loading = @_autoPageLoading
# loading sign handling
loading.increase()
successCallbackWrapper = (data) =>
if data.items.length == 0
@_preventUselessAutoPageRequest = true
successCallbackWrapper = (data) ->
onSuccess(data)
loading.decrease()
failureCallbackWrapper = (data) ->
@ -88,8 +85,7 @@ $rootScope, $q) ->
onSuccess: successCallbackWrapper
onFailure: failureCallbackWrapper
if not @_preventUselessAutoPageRequest
@_request.get 'news_items', params
@_request.get 'news_items', params
getNewItems: (type, id, lastModified, onSuccess) ->

Просмотреть файл

@ -1051,12 +1051,10 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
this._itemModel = _itemModel;
this._type = _type;
this._$rootScope = _$rootScope;
this._preventAutopage = false;
}
BusinessLayer.prototype.load = function(id) {
var _this = this;
this._preventAutopage = false;
this._$rootScope.$broadcast('loadingNewItems');
this._itemModel.clear();
this._persistence.getItems(this._type, id, 0, function() {
@ -2732,7 +2730,6 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
this._config = _config;
this._activeFeed = _activeFeed;
this._$rootScope = _$rootScope;
this._preventUselessAutoPageRequest = false;
}
Persistence.prototype.init = function() {
@ -2763,23 +2760,18 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
Persistence.prototype.getItems = function(type, id, offset, onSuccess) {
var failureCallbackWrapper, loading, params, successCallbackWrapper,
_this = this;
var failureCallbackWrapper, loading, params, successCallbackWrapper;
if (onSuccess == null) {
onSuccess = null;
}
onSuccess || (onSuccess = function() {});
if (offset === 0) {
this._preventUselessAutoPageRequest = false;
loading = this._feedLoading;
} else {
loading = this._autoPageLoading;
}
loading.increase();
successCallbackWrapper = function(data) {
if (data.items.length === 0) {
_this._preventUselessAutoPageRequest = true;
}
onSuccess(data);
return loading.decrease();
};
@ -2796,9 +2788,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
onSuccess: successCallbackWrapper,
onFailure: failureCallbackWrapper
};
if (!this._preventUselessAutoPageRequest) {
return this._request.get('news_items', params);
}
return this._request.get('news_items', params);
};
Persistence.prototype.getNewItems = function(type, id, lastModified, onSuccess) {

Просмотреть файл

@ -264,19 +264,3 @@ describe 'ItemBusinessLayer', ->
expect(@persistence.getNewItems).toHaveBeenCalledWith(
@FeedType.Feed, 3, 4, callback)
it 'should autopage the next items if there are none', =>
@NewestItem.handle(13)
@persistence.getItems = jasmine.createSpy('autopage')
callback = ->
@ItemModel.add({id: 2, guidHash: 'abc', feedId: 2, status: 16})
@ItemModel.add({id: 3, guidHash: 'abcd', feedId: 2, status: 16})
@ItemModel.add({id: 1, guidHash: 'abce', feedId: 2, status: 16})
@ItemModel.add({id: 6, guidHash: 'abcf', feedId: 2, status: 16})
@ItemBusinessLayer.loadNext(callback)
expect(@persistence.getItems).toHaveBeenCalledWith(
@FeedType.Feed, 3, 1, jasmine.any(Function))

Просмотреть файл

@ -74,37 +74,6 @@ describe 'Persistence', ->
expect(@req.get).toHaveBeenCalledWith('news_items', expected)
it 'should reset the autopage lock when loading a new feed', =>
data =
items: []
called = 0
@req.get.andCallFake (route, params) ->
params.onSuccess(data)
called++
success = ->
@Persistence.getItems(2, 3, 4, success)
@Persistence.getItems(2, 3, 0, success)
expect(called).toBe(2)
it 'should not send autopage request if reqeust returned nothing', =>
data =
items: []
called = 0
@req.get.andCallFake (route, params) ->
params.onSuccess(data)
called++
success = ->
@Persistence.getItems(2, 3, 4, success)
@Persistence.getItems(2, 3, 4, success)
expect(called).toBe(1)
it 'should send a load new items request', =>
success = ->
params =
@ -477,5 +446,3 @@ describe 'Persistence', ->
expect(@req.post).toHaveBeenCalledWith('news_usersettings_setcompact',
expected)