Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

only allow for one onOnline listener at a given time (#1896)

authored by

Jovi De Croock and committed by
GitHub
dbb52bd2 66d7fb78

+18 -3
+5
.changeset/strong-turkeys-approve.md
··· 1 + --- 2 + '@urql/exchange-graphcache': patch 3 + --- 4 + 5 + Cleanup the previous `onOnline` event-listener when called again
+13 -3
exchanges/graphcache/src/default-storage/index.ts
··· 34 34 export const makeDefaultStorage = (opts?: StorageOptions): DefaultStorage => { 35 35 if (!opts) opts = {}; 36 36 37 + let callback: (() => void) | undefined; 38 + 37 39 const DB_NAME = opts.idbName || 'graphcache-v4'; 38 40 const ENTRIES_STORE_NAME = 'entries'; 39 41 const METADATA_STORE_NAME = 'metadata'; ··· 195 197 }, 196 198 197 199 onOnline(cb: () => void) { 198 - window.addEventListener('online', () => { 199 - cb(); 200 - }); 200 + if (callback) { 201 + window.removeEventListener('online', callback); 202 + callback = undefined; 203 + } 204 + 205 + window.addEventListener( 206 + 'online', 207 + (callback = () => { 208 + cb(); 209 + }) 210 + ); 201 211 }, 202 212 }; 203 213 };