@tanstack/query-broadcast-client-experimental 5.0.0-alpha.48 → 5.0.0-alpha.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-broadcast-client-experimental",
3
- "version": "5.0.0-alpha.48",
3
+ "version": "5.0.0-alpha.49",
4
4
  "description": "An experimental plugin to for broadcasting the state of your queryClient between browser tabs/windows",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -13,7 +13,7 @@
13
13
  "type": "commonjs",
14
14
  "types": "build/lib/index.d.ts",
15
15
  "main": "build/lib/index.js",
16
- "module": "build/lib/index.esm.js",
16
+ "module": "build/lib/index.mjs",
17
17
  "exports": {
18
18
  ".": {
19
19
  "types": "./build/lib/index.d.ts",
@@ -1,76 +0,0 @@
1
- import { BroadcastChannel } from 'broadcast-channel';
2
-
3
- function broadcastQueryClient({
4
- queryClient,
5
- broadcastChannel = 'tanstack-query'
6
- }) {
7
- let transaction = false;
8
- const tx = cb => {
9
- transaction = true;
10
- cb();
11
- transaction = false;
12
- };
13
- const channel = new BroadcastChannel(broadcastChannel, {
14
- webWorkerSupport: false
15
- });
16
- const queryCache = queryClient.getQueryCache();
17
- queryClient.getQueryCache().subscribe(queryEvent => {
18
- if (transaction) {
19
- return;
20
- }
21
- const {
22
- query: {
23
- queryHash,
24
- queryKey,
25
- state
26
- }
27
- } = queryEvent;
28
- if (queryEvent.type === 'updated' && queryEvent.action.type === 'success') {
29
- channel.postMessage({
30
- type: 'updated',
31
- queryHash,
32
- queryKey,
33
- state
34
- });
35
- }
36
- if (queryEvent.type === 'removed') {
37
- channel.postMessage({
38
- type: 'removed',
39
- queryHash,
40
- queryKey
41
- });
42
- }
43
- });
44
- channel.onmessage = action => {
45
- if (!(action != null && action.type)) {
46
- return;
47
- }
48
- tx(() => {
49
- const {
50
- type,
51
- queryHash,
52
- queryKey,
53
- state
54
- } = action;
55
- if (type === 'updated') {
56
- const query = queryCache.get(queryHash);
57
- if (query) {
58
- query.setState(state);
59
- return;
60
- }
61
- queryCache.build(queryClient, {
62
- queryKey,
63
- queryHash
64
- }, state);
65
- } else if (type === 'removed') {
66
- const query = queryCache.get(queryHash);
67
- if (query) {
68
- queryCache.remove(query);
69
- }
70
- }
71
- });
72
- };
73
- }
74
-
75
- export { broadcastQueryClient };
76
- //# sourceMappingURL=index.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.js","sources":["../../src/index.ts"],"sourcesContent":["import { BroadcastChannel } from 'broadcast-channel'\nimport type { QueryClient } from '@tanstack/query-core'\n\ninterface BroadcastQueryClientOptions {\n queryClient: QueryClient\n broadcastChannel?: string\n}\n\nexport function broadcastQueryClient({\n queryClient,\n broadcastChannel = 'tanstack-query',\n}: BroadcastQueryClientOptions) {\n let transaction = false\n const tx = (cb: () => void) => {\n transaction = true\n cb()\n transaction = false\n }\n\n const channel = new BroadcastChannel(broadcastChannel, {\n webWorkerSupport: false,\n })\n\n const queryCache = queryClient.getQueryCache()\n\n queryClient.getQueryCache().subscribe((queryEvent) => {\n if (transaction) {\n return\n }\n\n const {\n query: { queryHash, queryKey, state },\n } = queryEvent\n\n if (queryEvent.type === 'updated' && queryEvent.action.type === 'success') {\n channel.postMessage({\n type: 'updated',\n queryHash,\n queryKey,\n state,\n })\n }\n\n if (queryEvent.type === 'removed') {\n channel.postMessage({\n type: 'removed',\n queryHash,\n queryKey,\n })\n }\n })\n\n channel.onmessage = (action) => {\n if (!action?.type) {\n return\n }\n\n tx(() => {\n const { type, queryHash, queryKey, state } = action\n\n if (type === 'updated') {\n const query = queryCache.get(queryHash)\n\n if (query) {\n query.setState(state)\n return\n }\n\n queryCache.build(\n queryClient,\n {\n queryKey,\n queryHash,\n },\n state,\n )\n } else if (type === 'removed') {\n const query = queryCache.get(queryHash)\n\n if (query) {\n queryCache.remove(query)\n }\n }\n })\n }\n}\n"],"names":["broadcastQueryClient","queryClient","broadcastChannel","transaction","tx","cb","channel","BroadcastChannel","webWorkerSupport","queryCache","getQueryCache","subscribe","queryEvent","query","queryHash","queryKey","state","type","action","postMessage","onmessage","get","setState","build","remove"],"mappings":";;AAQO,SAASA,oBAAoBA,CAAC;EACnCC,WAAW;AACXC,EAAAA,gBAAgB,GAAG,gBAAA;AACQ,CAAC,EAAE;EAC9B,IAAIC,WAAW,GAAG,KAAK,CAAA;EACvB,MAAMC,EAAE,GAAIC,EAAc,IAAK;AAC7BF,IAAAA,WAAW,GAAG,IAAI,CAAA;AAClBE,IAAAA,EAAE,EAAE,CAAA;AACJF,IAAAA,WAAW,GAAG,KAAK,CAAA;GACpB,CAAA;AAED,EAAA,MAAMG,OAAO,GAAG,IAAIC,gBAAgB,CAACL,gBAAgB,EAAE;AACrDM,IAAAA,gBAAgB,EAAE,KAAA;AACpB,GAAC,CAAC,CAAA;AAEF,EAAA,MAAMC,UAAU,GAAGR,WAAW,CAACS,aAAa,EAAE,CAAA;EAE9CT,WAAW,CAACS,aAAa,EAAE,CAACC,SAAS,CAAEC,UAAU,IAAK;AACpD,IAAA,IAAIT,WAAW,EAAE;AACf,MAAA,OAAA;AACF,KAAA;IAEA,MAAM;AACJU,MAAAA,KAAK,EAAE;QAAEC,SAAS;QAAEC,QAAQ;AAAEC,QAAAA,KAAAA;AAAM,OAAA;AACtC,KAAC,GAAGJ,UAAU,CAAA;AAEd,IAAA,IAAIA,UAAU,CAACK,IAAI,KAAK,SAAS,IAAIL,UAAU,CAACM,MAAM,CAACD,IAAI,KAAK,SAAS,EAAE;MACzEX,OAAO,CAACa,WAAW,CAAC;AAClBF,QAAAA,IAAI,EAAE,SAAS;QACfH,SAAS;QACTC,QAAQ;AACRC,QAAAA,KAAAA;AACF,OAAC,CAAC,CAAA;AACJ,KAAA;AAEA,IAAA,IAAIJ,UAAU,CAACK,IAAI,KAAK,SAAS,EAAE;MACjCX,OAAO,CAACa,WAAW,CAAC;AAClBF,QAAAA,I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