mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 02:42:26 -05:00
Allow custom interval on AJAX sections of page
Some pages with AJAX should update quickly, because the data is likely to be changing quickly, and be finished changing sooner. Other pages we want to have tick over a bit slower. This commit adds an optional ‘interval’ parameter to the updateContent modules, which sets how often the page should ping the server for an update. It then sets the interval for the dashboard page to be 10 seconds, rather than the default 1.5 seconds.
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
(function(GOVUK, Modules) {
|
||||
"use strict";
|
||||
|
||||
const interval = 1500; // milliseconds
|
||||
|
||||
GOVUK.timeCache = {};
|
||||
GOVUK.resultCache = {};
|
||||
|
||||
let getter = function(resource, render) {
|
||||
let getter = function(resource, interval, render) {
|
||||
|
||||
if (
|
||||
GOVUK.resultCache[resource] &&
|
||||
@@ -23,8 +21,8 @@
|
||||
|
||||
};
|
||||
|
||||
let poller = (resource, key, component) => () => getter(
|
||||
resource, response => component.html(response[key])
|
||||
let poller = (resource, key, component, interval) => () => getter(
|
||||
resource, interval, response => component.html(response[key])
|
||||
);
|
||||
|
||||
Modules.UpdateContent = function() {
|
||||
@@ -32,9 +30,10 @@
|
||||
this.start = function(component) {
|
||||
|
||||
const $component = $(component);
|
||||
interval = ($(component).data("interval-seconds") * 1000) || 1500;
|
||||
|
||||
setInterval(
|
||||
poller($component.data('resource'), $component.data('key'), $component),
|
||||
poller($component.data('resource'), $component.data('key'), $component, interval),
|
||||
interval / 5
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user