Add FetchStatus class.

We will use this in subsequent commits to replace the
`load_more_enabled` flag.
This commit is contained in:
Steve Howell
2018-03-09 16:04:07 -05:00
committed by Tim Abbott
parent ec305149be
commit fef2840531
5 changed files with 127 additions and 1 deletions

View File

@@ -91,6 +91,7 @@
"gear_menu": false,
"hashchange": false,
"hash_util": false,
"FetchStatus": false,
"message_list": false,
"Filter": false,
"flatpickr": false,

View File

@@ -0,0 +1,82 @@
var FetchStatus = zrequire('fetch_status');
var fetch_status = FetchStatus();
function reset() {
fetch_status = FetchStatus();
}
function can_load_newer() {
assert.equal(fetch_status.can_load_newer_messages(), true);
}
function blocked_newer() {
assert.equal(fetch_status.can_load_newer_messages(), false);
}
function can_load_older() {
assert.equal(fetch_status.can_load_older_messages(), true);
}
function blocked_older() {
assert.equal(fetch_status.can_load_older_messages(), false);
}
(function test_basics() {
reset();
can_load_older();
fetch_status.start_older_batch();
blocked_older();
can_load_newer();
fetch_status.finish_older_batch({
found_oldest: false,
});
can_load_older();
can_load_newer();
fetch_status.start_older_batch();
blocked_older();
can_load_newer();
fetch_status.finish_older_batch({
found_oldest: true,
});
blocked_older();
can_load_newer();
reset();
can_load_older();
can_load_newer();
fetch_status.start_newer_batch();
can_load_older();
blocked_newer();
fetch_status.finish_newer_batch({
found_newest: false,
});
can_load_older();
can_load_newer();
fetch_status.start_newer_batch();
can_load_older();
blocked_newer();
fetch_status.finish_newer_batch({
found_newest: true,
});
can_load_older();
blocked_newer();
}());

41
static/js/fetch_status.js Normal file
View File

@@ -0,0 +1,41 @@
var FetchStatus = function () {
var self = {};
var loading_older = false;
var loading_newer = false;
var found_oldest = false;
var found_newest = false;
self.start_older_batch = function () {
loading_older = true;
};
self.finish_older_batch = function (opts) {
loading_older = false;
found_oldest = opts.found_oldest;
};
self.can_load_older_messages = function () {
return !loading_older && !found_oldest;
};
self.start_newer_batch = function () {
loading_newer = true;
};
self.finish_newer_batch = function (opts) {
loading_newer = false;
found_newest = opts.found_newest;
};
self.can_load_newer_messages = function () {
return !loading_newer && !found_newest;
};
return self;
};
if (typeof module !== 'undefined') {
module.exports = FetchStatus;
}

View File

@@ -34,8 +34,9 @@ enforce_fully_covered = {
'static/js/composebox_typeahead.js',
'static/js/dict.js',
'static/js/emoji.js',
'static/js/filter.js',
'static/js/fenced_code.js',
'static/js/fetch_status.js',
'static/js/filter.js',
'static/js/hash_util.js',
'static/js/markdown.js',
'static/js/message_store.js',

View File

@@ -1026,6 +1026,7 @@ JS_SPECS = {
'js/top_left_corner.js',
'js/stream_list.js',
'js/filter.js',
'js/fetch_status.js',
'js/message_list_view.js',
'js/message_list.js',
'js/message_live_update.js',