the-forest/client/node_modules/.cache/babel-loader/997a72e8e7b99596050aa836bde534cb8bcb48f2b183bef45de6c7b675fbd7c6.json
2024-09-17 20:35:18 -04:00

1 line
5.1 KiB
JSON

{"ast":null,"code":"// src/onlineManager.ts\nimport { Subscribable } from \"./subscribable.js\";\nimport { isServer } from \"./utils.js\";\nvar OnlineManager = class extends Subscribable {\n #online = true;\n #cleanup;\n #setup;\n constructor() {\n super();\n this.#setup = onOnline => {\n if (!isServer && window.addEventListener) {\n const onlineListener = () => onOnline(true);\n const offlineListener = () => onOnline(false);\n window.addEventListener(\"online\", onlineListener, false);\n window.addEventListener(\"offline\", offlineListener, false);\n return () => {\n window.removeEventListener(\"online\", onlineListener);\n window.removeEventListener(\"offline\", offlineListener);\n };\n }\n return;\n };\n }\n onSubscribe() {\n if (!this.#cleanup) {\n this.setEventListener(this.#setup);\n }\n }\n onUnsubscribe() {\n if (!this.hasListeners()) {\n this.#cleanup?.();\n this.#cleanup = void 0;\n }\n }\n setEventListener(setup) {\n this.#setup = setup;\n this.#cleanup?.();\n this.#cleanup = setup(this.setOnline.bind(this));\n }\n setOnline(online) {\n const changed = this.#online !== online;\n if (changed) {\n this.#online = online;\n this.listeners.forEach(listener => {\n listener(online);\n });\n }\n }\n isOnline() {\n return this.#online;\n }\n};\nvar onlineManager = new OnlineManager();\nexport { OnlineManager, onlineManager };","map":{"version":3,"names":["Subscribable","isServer","OnlineManager","online","cleanup","setup","constructor","onOnline","window","addEventListener","onlineListener","offlineListener","removeEventListener","onSubscribe","setEventListener","onUnsubscribe","hasListeners","setOnline","bind","changed","listeners","forEach","listener","isOnline","onlineManager"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@tanstack/query-core/src/onlineManager.ts"],"sourcesContent":["import { Subscribable } from './subscribable'\nimport { isServer } from './utils'\n\ntype Listener = (online: boolean) => void\ntype SetupFn = (setOnline: Listener) => (() => void) | undefined\n\nexport class OnlineManager extends Subscribable<Listener> {\n #online = true\n #cleanup?: () => void\n\n #setup: SetupFn\n\n constructor() {\n super()\n this.#setup = (onOnline) => {\n // addEventListener does not exist in React Native, but window does\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isServer && window.addEventListener) {\n const onlineListener = () => onOnline(true)\n const offlineListener = () => onOnline(false)\n // Listen to online\n window.addEventListener('online', onlineListener, false)\n window.addEventListener('offline', offlineListener, false)\n\n return () => {\n // Be sure to unsubscribe if a new handler is set\n window.removeEventListener('online', onlineListener)\n window.removeEventListener('offline', offlineListener)\n }\n }\n\n return\n }\n }\n\n protected onSubscribe(): void {\n if (!this.#cleanup) {\n this.setEventListener(this.#setup)\n }\n }\n\n protected onUnsubscribe() {\n if (!this.hasListeners()) {\n this.#cleanup?.()\n this.#cleanup = undefined\n }\n }\n\n setEventListener(setup: SetupFn): void {\n this.#setup = setup\n this.#cleanup?.()\n this.#cleanup = setup(this.setOnline.bind(this))\n }\n\n setOnline(online: boolean): void {\n const changed = this.#online !== online\n\n if (changed) {\n this.#online = online\n this.listeners.forEach((listener) => {\n listener(online)\n })\n }\n }\n\n isOnline(): boolean {\n return this.#online\n }\n}\n\nexport const onlineManager = new OnlineManager()\n"],"mappings":";AAAA,SAASA,YAAA,QAAoB;AAC7B,SAASC,QAAA,QAAgB;AAKlB,IAAMC,aAAA,GAAN,cAA4BF,YAAA,CAAuB;EACxD,CAAAG,MAAA,GAAU;EACV,CAAAC,OAAA;EAEA,CAAAC,KAAA;EAEAC,YAAA,EAAc;IACZ,MAAM;IACN,KAAK,CAAAD,KAAA,GAAUE,QAAA,IAAa;MAG1B,IAAI,CAACN,QAAA,IAAYO,MAAA,CAAOC,gBAAA,EAAkB;QACxC,MAAMC,cAAA,GAAiBA,CAAA,KAAMH,QAAA,CAAS,IAAI;QAC1C,MAAMI,eAAA,GAAkBA,CAAA,KAAMJ,QAAA,CAAS,KAAK;QAE5CC,MAAA,CAAOC,gBAAA,CAAiB,UAAUC,cAAA,EAAgB,KAAK;QACvDF,MAAA,CAAOC,gBAAA,CA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