@tanstack/query-broadcast-client-experimental 4.36.1 → 4.39.0

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": "4.36.1",
3
+ "version": "4.39.0",
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",
@@ -33,12 +33,7 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "broadcast-channel": "^4.14.0",
36
- "@tanstack/query-core": "4.36.1"
36
+ "@tanstack/query-core": "4.39.0"
37
37
  },
38
- "scripts": {
39
- "clean": "rimraf ./build",
40
- "test:eslint": "eslint --ext .ts,.tsx ./src",
41
- "test:types": "tsc",
42
- "build:types": "tsc --build"
43
- }
38
+ "scripts": {}
44
39
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEvD,UAAU,2BAA2B;IACnC,WAAW,EAAE,WAAW,CAAA;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,OAAO,CAAC,EAAE,uBAAuB,CAAA;CAClC;AAED,wBAAgB,oBAAoB,CAAC,EACnC,WAAW,EACX,gBAAmC,EACnC,OAAO,GACR,EAAE,2BAA2B,QA2E7B"}
@@ -1,89 +0,0 @@
1
- import { BroadcastChannel } from 'broadcast-channel';
2
-
3
- function broadcastQueryClient({
4
- queryClient,
5
- broadcastChannel = 'tanstack-query',
6
- options
7
- }) {
8
- let transaction = false;
9
-
10
- const tx = cb => {
11
- transaction = true;
12
- cb();
13
- transaction = false;
14
- };
15
-
16
- const channel = new BroadcastChannel(broadcastChannel, {
17
- webWorkerSupport: false,
18
- ...options
19
- });
20
- const queryCache = queryClient.getQueryCache();
21
- queryClient.getQueryCache().subscribe(queryEvent => {
22
- if (transaction) {
23
- return;
24
- }
25
-
26
- const {
27
- query: {
28
- queryHash,
29
- queryKey,
30
- state
31
- }
32
- } = queryEvent;
33
-
34
- if (queryEvent.type === 'updated' && queryEvent.action.type === 'success') {
35
- channel.postMessage({
36
- type: 'updated',
37
- queryHash,
38
- queryKey,
39
- state
40
- });
41
- }
42
-
43
- if (queryEvent.type === 'removed') {
44
- channel.postMessage({
45
- type: 'removed',
46
- queryHash,
47
- queryKey
48
- });
49
- }
50
- });
51
-
52
- channel.onmessage = action => {
53
- if (!(action != null && action.type)) {
54
- return;
55
- }
56
-
57
- tx(() => {
58
- const {
59
- type,
60
- queryHash,
61
- queryKey,
62
- state
63
- } = action;
64
-
65
- if (type === 'updated') {
66
- const query = queryCache.get(queryHash);
67
-
68
- if (query) {
69
- query.setState(state);
70
- return;
71
- }
72
-
73
- queryCache.build(queryClient, {
74
- queryKey,
75
- queryHash
76
- }, state);
77
- } else if (type === 'removed') {
78
- const query = queryCache.get(queryHash);
79
-
80
- if (query) {
81
- queryCache.remove(query);
82
- }
83
- }
84
- });
85
- };
86
- }
87
-
88
- export { broadcastQueryClient };
89
- //# 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 { BroadcastChannelOptions } from 'broadcast-channel'\nimport type { QueryClient } from '@tanstack/query-core'\n\ninterface BroadcastQueryClientOptions {\n queryClient: QueryClient\n broadcastChannel?: string\n options?: BroadcastChannelOptions\n}\n\nexport function broadcastQueryClient({\n queryClient,\n broadcastChannel = 'tanstack-query',\n options,\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 ...options,\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","options","transaction","tx","cb","channel","BroadcastChannel","webWorkerSupport","queryCache","getQueryCache","subscribe","queryEvent","query","queryHash","queryKey","state","type","action","postMessage","onmessage","get","setState","build","remove"],"mappings":";;AAUO,SAASA,oBAAT,CAA8B;EACnCC,WADmC;AAEnCC,EAAAA,gBAAgB,GAAG,gBAFgB;AAGnCC,EAAAA,OAAAA;AAHmC,CAA9B,EAIyB;EAC9B,IAAIC,WAAW,GAAG,KAAlB,CAAA;;EACA,MAAMC,EAAE,GAAIC,EAAD,IAAoB;AAC7BF,IAAAA,WAAW,GAAG,IAAd,CAAA;IACAE,EAAE,EAAA,CAAA;AACFF,IAAAA,WAAW,GAAG,KAAd,CAAA;GAHF,CAAA;;AAMA,EAAA,MAAMG,OAAO,GAAG,IAAIC,gBAAJ,CAAqBN,gBAArB,EAAuC;AACrDO,IAAAA,gBAAgB,EAAE,KADmC;IAErD,GAAGN,OAAAA;AAFkD,GAAvC,CAAhB,CAAA;AA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;;AAEA,QAAA,IAAID,KAAJ,EAAW;UACTA,KAAK,CAACS,QAAN,CAAeN,KAAf,CAAA,CAAA;AACA,UAAA,OAAA;AACD,SAAA;;AAEDP,QAAAA,UAAU,CAACc,KAAX,CACEvB,WADF,EAEE;UACEe,QADF;AAEED,UAAAA,SAAAA;AAFF,SAFF,EAMEE,KANF,CAAA,CAAA;AAQD,OAhBD,MAgBO,IAAIC,IAAI,KAAK,SAAb,EAAwB;AAC7B,QAAA,MAAMJ,KAAK,GAAGJ,UAAU,CAACY,GAAX,CAAeP,SAAf,CAAd,CAAA;;AAEA,QAAA,IAAID,KAAJ,EAAW;UACTJ,UAAU,CAACe,MAAX,CAAkBX,KAAlB,CAAA,CAAA;AACD,SAAA;AACF,OAAA;AACF,KA1BC,CAAF,CAAA;GALF,CAAA;AAiCD;;;;"}
@@ -1,93 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var broadcastChannel = require('broadcast-channel');
6
-
7
- function broadcastQueryClient({
8
- queryClient,
9
- broadcastChannel: broadcastChannel$1 = 'tanstack-query',
10
- options
11
- }) {
12
- let transaction = false;
13
-
14
- const tx = cb => {
15
- transaction = true;
16
- cb();
17
- transaction = false;
18
- };
19
-
20
- const channel = new broadcastChannel.BroadcastChannel(broadcastChannel$1, {
21
- webWorkerSupport: false,
22
- ...options
23
- });
24
- const queryCache = queryClient.getQueryCache();
25
- queryClient.getQueryCache().subscribe(queryEvent => {
26
- if (transaction) {
27
- return;
28
- }
29
-
30
- const {
31
- query: {
32
- queryHash,
33
- queryKey,
34
- state
35
- }
36
- } = queryEvent;
37
-
38
- if (queryEvent.type === 'updated' && queryEvent.action.type === 'success') {
39
- channel.postMessage({
40
- type: 'updated',
41
- queryHash,
42
- queryKey,
43
- state
44
- });
45
- }
46
-
47
- if (queryEvent.type === 'removed') {
48
- channel.postMessage({
49
- type: 'removed',
50
- queryHash,
51
- queryKey
52
- });
53
- }
54
- });
55
-
56
- channel.onmessage = action => {
57
- if (!(action != null && action.type)) {
58
- return;
59
- }
60
-
61
- tx(() => {
62
- const {
63
- type,
64
- queryHash,
65
- queryKey,
66
- state
67
- } = action;
68
-
69
- if (type === 'updated') {
70
- const query = queryCache.get(queryHash);
71
-
72
- if (query) {
73
- query.setState(state);
74
- return;
75
- }
76
-
77
- queryCache.build(queryClient, {
78
- queryKey,
79
- queryHash
80
- }, state);
81
- } else if (type === 'removed') {
82
- const query = queryCache.get(queryHash);
83
-
84
- if (query) {
85
- queryCache.remove(query);
86
- }
87
- }
88
- });
89
- };
90
- }
91
-
92
- exports.broadcastQueryClient = broadcastQueryClient;
93
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { BroadcastChannel } from 'broadcast-channel'\nimport type { BroadcastChannelOptions } from 'broadcast-channel'\nimport type { QueryClient } from '@tanstack/query-core'\n\ninterface BroadcastQueryClientOptions {\n queryClient: QueryClient\n broadcastChannel?: string\n options?: BroadcastChannelOptions\n}\n\nexport function broadcastQueryClient({\n queryClient,\n broadcastChannel = 'tanstack-query',\n options,\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 ...options,\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","options","transaction","tx","cb","channel","BroadcastChannel","webWorkerSupport","queryCache","getQueryCache","subscribe","queryEvent","query","queryHash","queryKey","state","type","action","postMessage","onmessage","get","setState","build","remove"],"mappings":";;;;;;AAUO,SAASA,oBAAT,CAA8B;EACnCC,WADmC;AAEnCC,oBAAAA,kBAAgB,GAAG,gBAFgB;AAGnCC,EAAAA,OAAAA;AAHmC,CAA9B,EAIyB;EAC9B,IAAIC,WAAW,GAAG,KAAlB,CAAA;;EACA,MAAMC,EAAE,GAAIC,EAAD,IAAoB;AAC7BF,IAAAA,WAAW,GAAG,IAAd,CAAA;IACAE,EAAE,EAAA,CAAA;AACFF,IAAAA,WAAW,GAAG,KAAd,CAAA;GAHF,CAAA;;AAMA,EAAA,MAAMG,OAAO,GAAG,IAAIC,iCAAJ,CAAqBN,kBAArB,EAAuC;AACrDO,IAAAA,gBAAgB,EAAE,KADmC;IAErD,GAAGN,OAAAA;AAFkD,GAAvC,CAAhB,CAAA;AAKA,EAAA,MAAMO,UAAU,GAAGT,WAAW,CAACU,aAAZ,EAAnB,CAAA;AAEAV,EAAAA,WAAW,CAACU,aAAZ,EAAA,CAA4BC,SAA5B,CAAuCC,UAAD,IAAgB;AACpD,IAAA,IAAIT,WAAJ,EAAiB;AACf,MAAA,OAAA;AACD,KAAA;;IAED,MAAM;AACJU,MAAAA,KAAK,EAAE;QAAEC,SAAF;QAAaC,QAAb;AAAuBC,QAAAA,KAAAA;AAAvB,OAAA;AADH,KAAA,GAEFJ,UAFJ,CAAA;;AAIA,IAAA,IAAIA,UAAU,CAACK,IAAX,KAAoB,SAApB,IAAiCL,UAAU,CAACM,MAAX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ACe,MAAX,CAAkBX,KAAlB,CAAA,CAAA;AACD,SAAA;AACF,OAAA;AACF,KA1BC,CAAF,CAAA;GALF,CAAA;AAiCD;;;;"}
@@ -1,89 +0,0 @@
1
- import { BroadcastChannel } from 'broadcast-channel';
2
-
3
- function broadcastQueryClient({
4
- queryClient,
5
- broadcastChannel = 'tanstack-query',
6
- options
7
- }) {
8
- let transaction = false;
9
-
10
- const tx = cb => {
11
- transaction = true;
12
- cb();
13
- transaction = false;
14
- };
15
-
16
- const channel = new BroadcastChannel(broadcastChannel, {
17
- webWorkerSupport: false,
18
- ...options
19
- });
20
- const queryCache = queryClient.getQueryCache();
21
- queryClient.getQueryCache().subscribe(queryEvent => {
22
- if (transaction) {
23
- return;
24
- }
25
-
26
- const {
27
- query: {
28
- queryHash,
29
- queryKey,
30
- state
31
- }
32
- } = queryEvent;
33
-
34
- if (queryEvent.type === 'updated' && queryEvent.action.type === 'success') {
35
- channel.postMessage({
36
- type: 'updated',
37
- queryHash,
38
- queryKey,
39
- state
40
- });
41
- }
42
-
43
- if (queryEvent.type === 'removed') {
44
- channel.postMessage({
45
- type: 'removed',
46
- queryHash,
47
- queryKey
48
- });
49
- }
50
- });
51
-
52
- channel.onmessage = action => {
53
- if (!(action != null && action.type)) {
54
- return;
55
- }
56
-
57
- tx(() => {
58
- const {
59
- type,
60
- queryHash,
61
- queryKey,
62
- state
63
- } = action;
64
-
65
- if (type === 'updated') {
66
- const query = queryCache.get(queryHash);
67
-
68
- if (query) {
69
- query.setState(state);
70
- return;
71
- }
72
-
73
- queryCache.build(queryClient, {
74
- queryKey,
75
- queryHash
76
- }, state);
77
- } else if (type === 'removed') {
78
- const query = queryCache.get(queryHash);
79
-
80
- if (query) {
81
- queryCache.remove(query);
82
- }
83
- }
84
- });
85
- };
86
- }
87
-
88
- export { broadcastQueryClient };
89
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sources":["../../src/index.ts"],"sourcesContent":["import { BroadcastChannel } from 'broadcast-channel'\nimport type { BroadcastChannelOptions } from 'broadcast-channel'\nimport type { QueryClient } from '@tanstack/query-core'\n\ninterface BroadcastQueryClientOptions {\n queryClient: QueryClient\n broadcastChannel?: string\n options?: BroadcastChannelOptions\n}\n\nexport function broadcastQueryClient({\n queryClient,\n broadcastChannel = 'tanstack-query',\n options,\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 ...options,\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","options","transaction","tx","cb","channel","BroadcastChannel","webWorkerSupport","queryCache","getQueryCache","subscribe","queryEvent","query","queryHash","queryKey","state","type","action","postMessage","onmessage","get","setState","build","remove"],"mappings":";;AAUO,SAASA,oBAAT,CAA8B;EACnCC,WADmC;AAEnCC,EAAAA,gBAAgB,GAAG,gBAFgB;AAGnCC,EAAAA,OAAAA;AAHmC,CAA9B,EAIyB;EAC9B,IAAIC,WAAW,GAAG,K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MAAM,CAAED,IAAT,CAAJ,EAAmB;AACjB,MAAA,OAAA;AACD,KAAA;;AAEDb,IAAAA,EAAE,CAAC,MAAM;MACP,MAAM;QAAEa,IAAF;QAAQH,SAAR;QAAmBC,QAAnB;AAA6BC,QAAAA,KAAAA;AAA7B,OAAA,GAAuCE,MAA7C,CAAA;;MAEA,IAAID,IAAI,KAAK,SAAb,EAAwB;AACtB,QAAA,MAAMJ,KAAK,GAAGJ,UAAU,CAACY,GAAX,CAAeP,SAAf,CAAd,CAAA;;AAEA,QAAA,IAAID,KAAJ,EAAW;UACTA,KAAK,CAACS,QAAN,CAAeN,KAAf,CAAA,CAAA;AACA,UAAA,OAAA;AACD,SAAA;;AAEDP,QAAAA,UAAU,CAACc,KAAX,CACEvB,WADF,EAEE;UACEe,QADF;AAEED,UAAAA,SAAAA;AAFF,SAFF,EAMEE,KANF,CAAA,CAAA;AAQD,OAhBD,MAgBO,IAAIC,IAAI,KAAK,SAAb,EAAwB;AAC7B,QAAA,MAAMJ,KAAK,GAAGJ,UAAU,CAACY,GAAX,CAAeP,SAAf,CAAd,CAAA;;AAEA,QAAA,IAAID,KAAJ,EAAW;UACTJ,UAAU,CAACe,MAAX,CAAkBX,KAAlB,CAAA,CAAA;AACD,SAAA;AACF,OAAA;AACF,KA1BC,CAAF,CAAA;GALF,CAAA;AAiCD;;;;"}
@@ -1,97 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('broadcast-channel')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'broadcast-channel'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.QueryBroadcastClient = {}, global.BroadcastChannel));
5
- })(this, (function (exports, broadcastChannel) { 'use strict';
6
-
7
- function broadcastQueryClient({
8
- queryClient,
9
- broadcastChannel: broadcastChannel$1 = 'tanstack-query',
10
- options
11
- }) {
12
- let transaction = false;
13
-
14
- const tx = cb => {
15
- transaction = true;
16
- cb();
17
- transaction = false;
18
- };
19
-
20
- const channel = new broadcastChannel.BroadcastChannel(broadcastChannel$1, {
21
- webWorkerSupport: false,
22
- ...options
23
- });
24
- const queryCache = queryClient.getQueryCache();
25
- queryClient.getQueryCache().subscribe(queryEvent => {
26
- if (transaction) {
27
- return;
28
- }
29
-
30
- const {
31
- query: {
32
- queryHash,
33
- queryKey,
34
- state
35
- }
36
- } = queryEvent;
37
-
38
- if (queryEvent.type === 'updated' && queryEvent.action.type === 'success') {
39
- channel.postMessage({
40
- type: 'updated',
41
- queryHash,
42
- queryKey,
43
- state
44
- });
45
- }
46
-
47
- if (queryEvent.type === 'removed') {
48
- channel.postMessage({
49
- type: 'removed',
50
- queryHash,
51
- queryKey
52
- });
53
- }
54
- });
55
-
56
- channel.onmessage = action => {
57
- if (!(action != null && action.type)) {
58
- return;
59
- }
60
-
61
- tx(() => {
62
- const {
63
- type,
64
- queryHash,
65
- queryKey,
66
- state
67
- } = action;
68
-
69
- if (type === 'updated') {
70
- const query = queryCache.get(queryHash);
71
-
72
- if (query) {
73
- query.setState(state);
74
- return;
75
- }
76
-
77
- queryCache.build(queryClient, {
78
- queryKey,
79
- queryHash
80
- }, state);
81
- } else if (type === 'removed') {
82
- const query = queryCache.get(queryHash);
83
-
84
- if (query) {
85
- queryCache.remove(query);
86
- }
87
- }
88
- });
89
- };
90
- }
91
-
92
- exports.broadcastQueryClient = broadcastQueryClient;
93
-
94
- Object.defineProperty(exports, '__esModule', { value: true });
95
-
96
- }));
97
- //# sourceMappingURL=index.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.development.js","sources":["../../src/index.ts"],"sourcesContent":["import { BroadcastChannel } from 'broadcast-channel'\nimport type { BroadcastChannelOptions } from 'broadcast-channel'\nimport type { QueryClient } from '@tanstack/query-core'\n\ninterface BroadcastQueryClientOptions {\n queryClient: QueryClient\n broadcastChannel?: string\n options?: BroadcastChannelOptions\n}\n\nexport function broadcastQueryClient({\n queryClient,\n broadcastChannel = 'tanstack-query',\n options,\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 ...options,\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","options","transaction","tx","cb","channel","BroadcastChannel","webWorkerSupport","queryCache","getQueryCache","subscribe","queryEvent","query","queryHash","queryKey","state","type","action","postMessage","onmessage","get","setState","build","remove"],"mappings":";;;;;;EAUO,SAASA,oBAAT,CAA8B;IACnCC,WADmC;EAEnCC,oBAAAA,kBAAgB,GAAG,gBAFgB;EAGnCC,EAAAA,OAAAA;EAHmC,CAA9B,EAIyB;IAC9B,IAAIC,WAAW,GAAG,KAAlB,CAAA;;IACA,MAAMC,EAAE,GAAIC,EAAD,IAAoB;EAC7BF,IAAAA,WAAW,GAAG,IAAd,CAAA;MACAE,EAAE,EAAA,CAAA;EACFF,IAAAA,WAAW,GAAG,KAAd,CAAA;KAHF,CAAA;;EAMA,EAAA,MAAMG,OAAO,GAAG,IAAIC,i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;QAEA,IAAID,IAAI,KAAK,SAAb,EAAwB;EACtB,QAAA,MAAMJ,KAAK,GAAGJ,UAAU,CAACY,GAAX,CAAeP,SAAf,CAAd,CAAA;;EAEA,QAAA,IAAID,KAAJ,EAAW;YACTA,KAAK,CAACS,QAAN,CAAeN,KAAf,CAAA,CAAA;EACA,UAAA,OAAA;EACD,SAAA;;EAEDP,QAAAA,UAAU,CAACc,KAAX,CACEvB,WADF,EAEE;YACEe,QADF;EAEED,UAAAA,SAAAA;EAFF,SAFF,EAMEE,KANF,CAAA,CAAA;EAQD,OAhBD,MAgBO,IAAIC,IAAI,KAAK,SAAb,EAAwB;EAC7B,QAAA,MAAMJ,KAAK,GAAGJ,UAAU,CAACY,GAAX,CAAeP,SAAf,CAAd,CAAA;;EAEA,QAAA,IAAID,KAAJ,EAAW;YACTJ,UAAU,CAACe,MAAX,CAAkBX,KAAlB,CAAA,CAAA;EACD,SAAA;EACF,OAAA;EACF,KA1BC,CAAF,CAAA;KALF,CAAA;EAiCD;;;;;;;;;;"}
@@ -1,2 +0,0 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("broadcast-channel")):"function"==typeof define&&define.amd?define(["exports","broadcast-channel"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).QueryBroadcastClient={},e.BroadcastChannel)}(this,(function(e,t){"use strict";e.broadcastQueryClient=function({queryClient:e,broadcastChannel:s="tanstack-query",options:r}){let a=!1;const n=new t.BroadcastChannel(s,{webWorkerSupport:!1,...r}),o=e.getQueryCache();e.getQueryCache().subscribe((e=>{if(a)return;const{query:{queryHash:t,queryKey:s,state:r}}=e;"updated"===e.type&&"success"===e.action.type&&n.postMessage({type:"updated",queryHash:t,queryKey:s,state:r}),"removed"===e.type&&n.postMessage({type:"removed",queryHash:t,queryKey:s})})),n.onmessage=t=>{null!=t&&t.type&&(a=!0,(()=>{const{type:s,queryHash:r,queryKey:a,state:n}=t;if("updated"===s){const t=o.get(r);if(t)return void t.setState(n);o.build(e,{queryKey:a,queryHash:r},n)}else if("removed"===s){const e=o.get(r);e&&o.remove(e)}})(),a=!1)}},Object.defineProperty(e,"__esModule",{value:!0})}));
2
- //# sourceMappingURL=index.production.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.production.js","sources":["../../src/index.ts"],"sourcesContent":["import { BroadcastChannel } from 'broadcast-channel'\nimport type { BroadcastChannelOptions } from 'broadcast-channel'\nimport type { QueryClient } from '@tanstack/query-core'\n\ninterface BroadcastQueryClientOptions {\n queryClient: QueryClient\n broadcastChannel?: string\n options?: BroadcastChannelOptions\n}\n\nexport function broadcastQueryClient({\n queryClient,\n broadcastChannel = 'tanstack-query',\n options,\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 ...options,\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":["queryClient","broadcastChannel","options","transaction","channel","BroadcastChannel","webWorkerSupport","queryCache","getQueryCache","subscribe","queryEvent","query","queryHash","queryKey","state","type","action","postMessage","onmessage","get","setState","build","remove","cb"],"mappings":"yVAUO,UAA8BA,YACnCA,EACAC,iBAAAA,EAAmB,iBAFgBC,QAGnCA,IAEA,IAAIC,GAAc,EAClB,MAMMC,EAAU,IAAIC,EAAJA,iBAAqBJ,EAAkB,CACrDK,kBAAkB,KACfJ,IAGCK,EAAaP,EAAYQ,gBAE/BR,EAAYQ,gBAAgBC,WAAWC,IACrC,GAAIP,EACF,OAGF,MACEQ,OAAOC,UAAEA,EAAFC,SAAaA,EAAbC,MAAuBA,IAC5BJ,EAEoB,YAApBA,EAAWK,MAAiD,YAA3BL,EAAWM,OAAOD,MACrDX,EAAQa,YAAY,CAClBF,KAAM,UACNH,YACAC,WACAC,UAIoB,YAApBJ,EAAWK,MACbX,EAAQa,YAAY,CAClBF,KAAM,UACNH,YACAC,gBAKNT,EAAQc,UAAaF,IACf,MAACA,GAAAA,EAAQD,OAxCbZ,GAAc,EA4CX,MACD,MAAMY,KAAEA,EAAFH,UAAQA,EAARC,SAAmBA,EAAnBC,MAA6BA,GAAUE,EAE7C,GAAa,YAATD,EAAoB,CACtB,MAAMJ,EAAQJ,EAAWY,IAAIP,GAE7B,GAAID,EAEF,YADAA,EAAMS,SAASN,GAIjBP,EAAWc,MACTrB,EACA,CACEa,WACAD,aAEFE,QAEG,GAAa,YAATC,EAAoB,CAC7B,MAAMJ,EAAQJ,EAAWY,IAAIP,GAEzBD,GACFJ,EAAWe,OAAOX,KAlExBY,GACApB,GAAc"}