Skip to content

Commit ae846fa

Browse files
committed
Make Obs configurable
1 parent 6ff18ba commit ae846fa

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

obj.js renamed to obs.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
// Store state in a global `obs` object for reuse later in your application.
1717
window.obs = window.obs || {};
1818

19+
const obsConfig = (window.obs && window.obs.config) || {};
20+
const observeChanges = obsConfig.observeChanges !== false;
21+
1922
// Helper function:
2023
// Bucket RTT into the nearest upper 25ms. E.g. an RTT of 108ms would be put
2124
// into the 125ms bucket. Think of 125ms as being 100–125ms.
@@ -99,7 +102,7 @@
99102
refreshConnectionStatus();
100103

101104
// Listen out for network condition changes and rerun the function.
102-
if (connection && typeof connection.addEventListener === 'function') {
105+
if (observeChanges && connection?.addEventListener) {
103106
connection.addEventListener('change', refreshConnectionStatus);
104107
}
105108

@@ -137,13 +140,9 @@
137140
refreshBatteryStatus(battery);
138141

139142
// Listen out for battery changes and rerun the function.
140-
if (typeof battery.addEventListener === 'function') {
141-
battery.addEventListener('levelchange', () =>
142-
refreshBatteryStatus(battery)
143-
);
144-
battery.addEventListener('chargingchange', () =>
145-
refreshBatteryStatus(battery)
146-
);
143+
if (observeChanges && typeof battery.addEventListener === 'function') {
144+
battery.addEventListener('levelchange', () => refreshBatteryStatus(battery));
145+
battery.addEventListener('chargingchange', () => refreshBatteryStatus(battery));
147146
}
148147
})
149148

0 commit comments

Comments
 (0)