File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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.
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
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
You can’t perform that action at this time.
0 commit comments