You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
870 B
37 lines
870 B
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
}); // from swr
|
|
|
|
var index_1 = require("./index");
|
|
|
|
var listeners = [];
|
|
|
|
function subscribe(listener) {
|
|
listeners.push(listener);
|
|
return function unsubscribe() {
|
|
var index = listeners.indexOf(listener);
|
|
listeners.splice(index, 1);
|
|
};
|
|
}
|
|
|
|
var eventsBinded = false;
|
|
|
|
if (typeof window !== 'undefined' && window.addEventListener && !eventsBinded) {
|
|
var revalidate = function revalidate() {
|
|
if (!index_1.isDocumentVisible() || !index_1.isOnline()) return;
|
|
|
|
for (var i = 0; i < listeners.length; i++) {
|
|
var listener = listeners[i];
|
|
listener();
|
|
}
|
|
};
|
|
|
|
window.addEventListener('visibilitychange', revalidate, false);
|
|
window.addEventListener('focus', revalidate, false); // only bind the events once
|
|
|
|
eventsBinded = true;
|
|
}
|
|
|
|
exports["default"] = subscribe; |