Skip to content

Commit

Permalink
Reduce number of requests to server by waiting 200 ms for user to end…
Browse files Browse the repository at this point in the history
… typing.
  • Loading branch information
krassowski committed Oct 8, 2017
1 parent db5a0b1 commit 410e5e9
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions website/static/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ var AsyncFiltersHandler = function()
{
var config;
var form;
var old_filters_query;
var current_state_checksum;

/**
Expand Down Expand Up @@ -190,7 +189,7 @@ var AsyncFiltersHandler = function()

if (!(is_response_actual(filters_data) && does_response_differ_from_current_state(filters_data)) && !from_future)
{
console.log('Skipping not actual response');
console.log('Skipping outdated response');
return
}
current_state_checksum = filters_data.checksum
Expand Down Expand Up @@ -251,8 +250,6 @@ var AsyncFiltersHandler = function()

}
});

old_filters_query = filters_query;
}

/**
Expand All @@ -279,6 +276,7 @@ var AsyncFiltersHandler = function()
* @property {function} data_handler
* @property {function} on_loading_start
* @property {function} on_loading_end
* @property {number} input_delay
* @property {jQuery} links_to_update
* @property {string} endpoint_url - an URL of endpoint returning {@see ServerResponse}
* the endpoint should accept checksum, (and return in {@see FiltersData})
Expand All @@ -299,12 +297,27 @@ var AsyncFiltersHandler = function()
'select, input:not([type=text]):not(.programmatic)',
function() { on_update() }
);

var timer;

form.on(
'input',
'input[type=text]:not(.programmatic)',
function() { on_update() }
function() {

if(timer)
window.clearTimeout(timer)

timer = window.setTimeout(
function(){
timer = null
on_update()
},
config.input_delay || 200
)
}
);
old_filters_query = serialize_form(form);

form.find('.save').hide()

update_history(window.location.search.substring(1), true)
Expand Down

0 comments on commit 410e5e9

Please sign in to comment.