!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).ReactQueryBroadcastQueryClientExperimental={})}(this,(function(e){"use strict";function n(e){return e||(e=0),new Promise((function(n){return setTimeout(n,e)}))}function t(){return Math.random().toString(36).substring(2)}var r=0,o=0;function s(){var e=(new Date).getTime();return e===r?1e3*e+ ++o:(r=e,o=0,1e3*e)}var i="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0);var a={create:function(e){var n={messagesCallback:null,bc:new BroadcastChannel(e),subFns:[]};return n.bc.onmessage=function(e){n.messagesCallback&&n.messagesCallback(e.data)},n},close:function(e){e.bc.close(),e.subFns=[]},onMessage:function(e,n){e.messagesCallback=n},postMessage:function(e,n){e.bc.postMessage(n,!1)},canBeUsed:function(){if(i&&"undefined"==typeof window)return!1;if("function"==typeof BroadcastChannel){if(BroadcastChannel._pubkey)throw new Error("BroadcastChannel: Do not overwrite window.BroadcastChannel with this module, this is not a polyfill");return!0}return!1},type:"native",averageResponseTime:function(){return 150},microSeconds:s},u=function(e){var n=new Set,t=new Map;this.has=n.has.bind(n),this.add=function(r){t.set(r,c()),n.add(r),function(){var r=c()-e,o=n[Symbol.iterator]();for(;;){var s=o.next().value;if(!s)return;if(!(t.get(s)0&&void 0!==arguments[0]?arguments[0]:{},n=JSON.parse(JSON.stringify(e));return void 0===n.webWorkerSupport&&(n.webWorkerSupport=!0),n.idb||(n.idb={}),n.idb.ttl||(n.idb.ttl=45e3),n.idb.fallbackInterval||(n.idb.fallbackInterval=150),e.idb&&"function"==typeof e.idb.onclose&&(n.idb.onclose=e.idb.onclose),n.localstorage||(n.localstorage={}),n.localstorage.removeTimeout||(n.localstorage.removeTimeout=6e4),e.methods&&(n.methods=e.methods),n.node||(n.node={}),n.node.ttl||(n.node.ttl=12e4),void 0===n.node.useFastPath&&(n.node.useFastPath=!0),n}function l(){if("undefined"!=typeof indexedDB)return indexedDB;if("undefined"!=typeof window){if(void 0!==window.mozIndexedDB)return window.mozIndexedDB;if(void 0!==window.webkitIndexedDB)return window.webkitIndexedDB;if(void 0!==window.msIndexedDB)return window.msIndexedDB}return!1}function f(e,n){var t=e.transaction("messages").objectStore("messages"),r=[];return new Promise((function(e){(function(){try{var e=IDBKeyRange.bound(n+1,1/0);return t.openCursor(e)}catch(e){return t.openCursor()}}()).onsuccess=function(t){var o=t.target.result;o?o.value.ide.lastCursorId&&(e.lastCursorId=n.id),n})).filter((function(n){return function(e,n){return e.uuid!==n.uuid&&(!n.eMIs.has(e.id)&&!(e.data.time0||e._addEL.internal.length>0}function E(e,n,t){e._addEL[n].push(t),function(e){if(!e._iL&&B(e)){var n=function(n){e._addEL[n.type].forEach((function(e){n.time>=e.time&&e.fn(n.data)}))},t=e.method.microSeconds();e._prepP?e._prepP.then((function(){e._iL=!0,e.method.onMessage(e._state,n,t)})):(e._iL=!0,e.method.onMessage(e._state,n,t))}}(e)}function L(e,n,t){e._addEL[n]=e._addEL[n].filter((function(e){return e!==t})),function(e){if(e._iL&&!B(e)){e._iL=!1;var n=e.method.microSeconds();e.method.onMessage(e._state,null,n)}}(e)}M._pubkey=!0,M.prototype={postMessage:function(e){if(this.closed)throw new Error("BroadcastChannel.postMessage(): Cannot post message after channel has closed");return S(this,"message",e)},postInternal:function(e){return S(this,"internal",e)},set onmessage(e){var n={time:this.method.microSeconds(),fn:e};L(this,"message",this._onML),e&&"function"==typeof e?(this._onML=n,E(this,"message",n)):this._onML=null},addEventListener:function(e,n){E(this,e,{time:this.method.microSeconds(),fn:n})},removeEventListener:function(e,n){L(this,e,this._addEL[e].find((function(e){return e.fn===n})))},close:function(){var e=this;if(!this.closed){this.closed=!0;var n=this._prepP?this._prepP:Promise.resolve();return this._onML=null,this._addEL.message=[],n.then((function(){return Promise.all(e._befC.map((function(e){return e()})))})).then((function(){return e.method.close(e._state)}))}},get type(){return this.method.type}},e.broadcastQueryClient=function(e){var n=e.queryClient,t=e.broadcastChannel,r=!1,o=new M(void 0===t?"react-query":t,{webWorkerSupport:!1}),s=n.getQueryCache();n.getQueryCache().subscribe((function(e){var n;if(!r&&(null==e?void 0:e.query)){var t=e.query,s=t.queryHash,i=t.queryKey,a=t.state;"queryUpdated"===e.type&&"success"===(null==(n=e.action)?void 0:n.type)&&o.postMessage({type:"queryUpdated",queryHash:s,queryKey:i,state:a}),"queryRemoved"===e.type&&o.postMessage({type:"queryRemoved",queryHash:s,queryKey:i})}})),o.onmessage=function(e){(null==e?void 0:e.type)&&(r=!0,function(){var t=e.type,r=e.queryHash,o=e.queryKey,i=e.state;if("queryUpdated"===t){var a=s.get(r);if(a)return void a.setState(i);s.build(n,{queryKey:o,queryHash:r},i)}else if("queryRemoved"===t){var u=s.get(r);u&&s.remove(u)}}(),r=!1)}},Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=broadcastQueryClient-experimental.production.min.js.map