@tanstack/query-broadcast-client-experimental 4.24.10 → 5.0.0-alpha.1

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.
@@ -5,13 +5,11 @@ function broadcastQueryClient({
5
5
  broadcastChannel = 'tanstack-query'
6
6
  }) {
7
7
  let transaction = false;
8
-
9
8
  const tx = cb => {
10
9
  transaction = true;
11
10
  cb();
12
11
  transaction = false;
13
12
  };
14
-
15
13
  const channel = new BroadcastChannel(broadcastChannel, {
16
14
  webWorkerSupport: false
17
15
  });
@@ -20,7 +18,6 @@ function broadcastQueryClient({
20
18
  if (transaction) {
21
19
  return;
22
20
  }
23
-
24
21
  const {
25
22
  query: {
26
23
  queryHash,
@@ -28,7 +25,6 @@ function broadcastQueryClient({
28
25
  state
29
26
  }
30
27
  } = queryEvent;
31
-
32
28
  if (queryEvent.type === 'updated' && queryEvent.action.type === 'success') {
33
29
  channel.postMessage({
34
30
  type: 'updated',
@@ -37,7 +33,6 @@ function broadcastQueryClient({
37
33
  state
38
34
  });
39
35
  }
40
-
41
36
  if (queryEvent.type === 'removed') {
42
37
  channel.postMessage({
43
38
  type: 'removed',
@@ -46,12 +41,10 @@ function broadcastQueryClient({
46
41
  });
47
42
  }
48
43
  });
49
-
50
44
  channel.onmessage = action => {
51
- if (!(action != null && action.type)) {
45
+ if (!action?.type) {
52
46
  return;
53
47
  }
54
-
55
48
  tx(() => {
56
49
  const {
57
50
  type,
@@ -59,22 +52,18 @@ function broadcastQueryClient({
59
52
  queryKey,
60
53
  state
61
54
  } = action;
62
-
63
55
  if (type === 'updated') {
64
56
  const query = queryCache.get(queryHash);
65
-
66
57
  if (query) {
67
58
  query.setState(state);
68
59
  return;
69
60
  }
70
-
71
61
  queryCache.build(queryClient, {
72
62
  queryKey,
73
63
  queryHash
74
64
  }, state);
75
65
  } else if (type === 'removed') {
76
66
  const query = queryCache.get(queryHash);
77
-
78
67
  if (query) {
79
68
  queryCache.remove(query);
80
69
  }
@@ -1 +1 @@
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,oBAAT,CAA8B;EACnCC,WADmC;AAEnCC,EAAAA,gBAAgB,GAAG,gBAAA;AAFgB,CAA9B,EAGyB;EAC9B,IAAIC,WAAW,GAAG,KAAlB,CAAA;;EACA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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,CACEtB,WADF,EAEE;UACEc,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
+ {"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,oBAAoB,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;AAE9CT,EAAAA,WAAW,CAACS,aAAa,EAAE,CAACC,SAAS,CAAEC,UAAU,IAAK;AACpD,IAAA,IAAIT,WAAW,EAAE;AACf,MAAA,O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,IAAIC,IAAI,KAAK,SAAS,EAAE;AAC7B,QAAA,MAAMJ,KAAK,GAAGJ,UAAU,CAACY,GAAG,CAACP,SAAS,CAAC,CAAA;AAEvC,QAAA,IAAID,KAAK,EAAE;AACTJ,UAAAA,UAAU,CAACe,MAAM,CAACX,KAAK,CAAC,CAAA;AAC1B,SAAA;AACF,OAAA;AACF,KAAC,CAAC,CAAA;GACH,CAAA;AACH;;;;"}
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var broadcastChannel = require('broadcast-channel');
6
4
 
7
5
  function broadcastQueryClient({
@@ -9,13 +7,11 @@ function broadcastQueryClient({
9
7
  broadcastChannel: broadcastChannel$1 = 'tanstack-query'
10
8
  }) {
11
9
  let transaction = false;
12
-
13
10
  const tx = cb => {
14
11
  transaction = true;
15
12
  cb();
16
13
  transaction = false;
17
14
  };
18
-
19
15
  const channel = new broadcastChannel.BroadcastChannel(broadcastChannel$1, {
20
16
  webWorkerSupport: false
21
17
  });
@@ -24,7 +20,6 @@ function broadcastQueryClient({
24
20
  if (transaction) {
25
21
  return;
26
22
  }
27
-
28
23
  const {
29
24
  query: {
30
25
  queryHash,
@@ -32,7 +27,6 @@ function broadcastQueryClient({
32
27
  state
33
28
  }
34
29
  } = queryEvent;
35
-
36
30
  if (queryEvent.type === 'updated' && queryEvent.action.type === 'success') {
37
31
  channel.postMessage({
38
32
  type: 'updated',
@@ -41,7 +35,6 @@ function broadcastQueryClient({
41
35
  state
42
36
  });
43
37
  }
44
-
45
38
  if (queryEvent.type === 'removed') {
46
39
  channel.postMessage({
47
40
  type: 'removed',
@@ -50,12 +43,10 @@ function broadcastQueryClient({
50
43
  });
51
44
  }
52
45
  });
53
-
54
46
  channel.onmessage = action => {
55
- if (!(action != null && action.type)) {
47
+ if (!action?.type) {
56
48
  return;
57
49
  }
58
-
59
50
  tx(() => {
60
51
  const {
61
52
  type,
@@ -63,22 +54,18 @@ function broadcastQueryClient({
63
54
  queryKey,
64
55
  state
65
56
  } = action;
66
-
67
57
  if (type === 'updated') {
68
58
  const query = queryCache.get(queryHash);
69
-
70
59
  if (query) {
71
60
  query.setState(state);
72
61
  return;
73
62
  }
74
-
75
63
  queryCache.build(queryClient, {
76
64
  queryKey,
77
65
  queryHash
78
66
  }, state);
79
67
  } else if (type === 'removed') {
80
68
  const query = queryCache.get(queryHash);
81
-
82
69
  if (query) {
83
70
  queryCache.remove(query);
84
71
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.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,oBAAT,CAA8B;EACnCC,WADmC;AAEnCC,oBAAAA,kBAAgB,GAAG,gBAAA;AAFgB,CAA9B,EAGyB;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,CAAqBL,kBAArB,EAAuC;AACrDM,IAAAA,gBAAgB,EAAE,KAAA;AADmC,GAAvC,CAAhB,CAAA;AAIA,EAAA,MAAMC,UAAU,GAAGR,WAAW,CAACS,aAAZ,EAAnB,CAAA;AAEAT,EAAAA,WAAW,CAACS,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,CAAkBD,IAAlB,KAA2B,SAAhE,EAA2E;MACzEX,OAAO,CAACa,WAAR,CAAoB;AAClBF,QAAAA,IAAI,EAAE,SADY;QAElBH,SAFkB;QAGlBC,QAHkB;AAIlBC,QAAAA,KAAAA;OAJF,CAAA,CAAA;AAMD,KAAA;;AAED,IAAA,IAAIJ,UAAU,CAACK,IAAX,KAAoB,SAAxB,EAAmC;MACjCX,OAAO,CAACa,WAAR,CAAoB;AAClBF,QAAAA,IAAI,EAAE,SADY;QAElBH,SAFkB;AAGlBC,QAAAA,QAAAA;OAHF,CAAA,CAAA;AAKD,KAAA;GAxBH,CAAA,CAAA;;AA2BAT,EAAAA,OAAO,CAACc,SAAR,GAAqBF,MAAD,IAAY;AAC9B,IAAA,IAAI,EAACA,MAAD,IAAA,IAAA,IAACA,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,CACEtB,WADF,EAEE;UACEc,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
+ {"version":3,"file":"index.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,oBAAoB,CAAC;EACnCC,WAAW;AACXC,oBAAAA,kBAAgB,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;A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KAAK,GAAGJ,UAAU,CAACY,GAAG,CAACP,SAAS,CAAC,CAAA;AAEvC,QAAA,IAAID,KAAK,EAAE;AACTA,UAAAA,KAAK,CAACS,QAAQ,CAACN,KAAK,CAAC,CAAA;AACrB,UAAA,OAAA;AACF,SAAA;AAEAP,QAAAA,UAAU,CAACc,KAAK,CACdtB,WAAW,EACX;UACEc,QAAQ;AACRD,UAAAA,SAAAA;SACD,EACDE,KAAK,CACN,CAAA;AACH,OAAC,MAAM,IAAIC,IAAI,KAAK,SAAS,EAAE;AAC7B,QAAA,MAAMJ,KAAK,GAAGJ,UAAU,CAACY,GAAG,CAACP,SAAS,CAAC,CAAA;AAEvC,QAAA,IAAID,KAAK,EAAE;AACTJ,UAAAA,UAAU,CAACe,MAAM,CAACX,KAAK,CAAC,CAAA;AAC1B,SAAA;AACF,OAAA;AACF,KAAC,CAAC,CAAA;GACH,CAAA;AACH;;;;"}
@@ -5,13 +5,11 @@ function broadcastQueryClient({
5
5
  broadcastChannel = 'tanstack-query'
6
6
  }) {
7
7
  let transaction = false;
8
-
9
8
  const tx = cb => {
10
9
  transaction = true;
11
10
  cb();
12
11
  transaction = false;
13
12
  };
14
-
15
13
  const channel = new BroadcastChannel(broadcastChannel, {
16
14
  webWorkerSupport: false
17
15
  });
@@ -20,7 +18,6 @@ function broadcastQueryClient({
20
18
  if (transaction) {
21
19
  return;
22
20
  }
23
-
24
21
  const {
25
22
  query: {
26
23
  queryHash,
@@ -28,7 +25,6 @@ function broadcastQueryClient({
28
25
  state
29
26
  }
30
27
  } = queryEvent;
31
-
32
28
  if (queryEvent.type === 'updated' && queryEvent.action.type === 'success') {
33
29
  channel.postMessage({
34
30
  type: 'updated',
@@ -37,7 +33,6 @@ function broadcastQueryClient({
37
33
  state
38
34
  });
39
35
  }
40
-
41
36
  if (queryEvent.type === 'removed') {
42
37
  channel.postMessage({
43
38
  type: 'removed',
@@ -46,12 +41,10 @@ function broadcastQueryClient({
46
41
  });
47
42
  }
48
43
  });
49
-
50
44
  channel.onmessage = action => {
51
- if (!(action != null && action.type)) {
45
+ if (!action?.type) {
52
46
  return;
53
47
  }
54
-
55
48
  tx(() => {
56
49
  const {
57
50
  type,
@@ -59,22 +52,18 @@ function broadcastQueryClient({
59
52
  queryKey,
60
53
  state
61
54
  } = action;
62
-
63
55
  if (type === 'updated') {
64
56
  const query = queryCache.get(queryHash);
65
-
66
57
  if (query) {
67
58
  query.setState(state);
68
59
  return;
69
60
  }
70
-
71
61
  queryCache.build(queryClient, {
72
62
  queryKey,
73
63
  queryHash
74
64
  }, state);
75
65
  } else if (type === 'removed') {
76
66
  const query = queryCache.get(queryHash);
77
-
78
67
  if (query) {
79
68
  queryCache.remove(query);
80
69
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","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,oBAAT,CAA8B;EACnCC,WADmC;AAEnCC,EAAAA,gBAAgB,GAAG,gBAAA;AAFgB,CAA9B,EAGyB;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,CAAqBL,gBAArB,EAAuC;AACrDM,IAAAA,gBAAgB,EAAE,KAAA;AADmC,GAAvC,CAAhB,CAAA;AAIA,EAAA,MAAMC,UAAU,GAAGR,WAAW,CAACS,aAAZ,EAAnB,CAAA;AAEAT,EAAAA,WAAW,CAACS,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,CAAkBD,IAAlB,KAA2B,SAAhE,EAA2E;MACzEX,OAAO,CAACa,WAAR,CAAoB;AAClBF,QAAAA,IAAI,EAAE,SADY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;;;"}
1
+ {"version":3,"file":"index.mjs","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,oBAAoB,CAAC;EACnCC,WAAW;AACXC,EAAAA,gBAAgB,GAAG,gBAAA;AACQ,CAAC,EAAE;EAC9B,IAAIC,WAAW,GAAG,KAAK,CAAA;EACvB,MAAMC,EAAE,GAAIC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AEH,SAAS;QAAEC,QAAQ;AAAEC,QAAAA,KAAAA;AAAM,OAAC,GAAGE,MAAM,CAAA;MAEnD,IAAID,IAAI,KAAK,SAAS,EAAE;AACtB,QAAA,MAAMJ,KAAK,GAAGJ,UAAU,CAACY,GAAG,CAACP,SAAS,CAAC,CAAA;AAEvC,QAAA,IAAID,KAAK,EAAE;AACTA,UAAAA,KAAK,CAACS,QAAQ,CAACN,KAAK,CAAC,CAAA;AACrB,UAAA,OAAA;AACF,SAAA;AAEAP,QAAAA,UAAU,CAACc,KAAK,CACdtB,WAAW,EACX;UACEc,QAAQ;AACRD,UAAAA,SAAAA;SACD,EACDE,KAAK,CACN,CAAA;AACH,OAAC,MAAM,IAAIC,IAAI,KAAK,SAAS,EAAE;AAC7B,QAAA,MAAMJ,KAAK,GAAGJ,UAAU,CAACY,GAAG,CAACP,SAAS,CAAC,CAAA;AAEvC,QAAA,IAAID,KAAK,EAAE;AACTJ,UAAAA,UAAU,CAACe,MAAM,CAACX,KAAK,CAAC,CAAA;AAC1B,SAAA;AACF,OAAA;AACF,KAAC,CAAC,CAAA;GACH,CAAA;AACH;;;;"}
@@ -9,13 +9,11 @@
9
9
  broadcastChannel: broadcastChannel$1 = 'tanstack-query'
10
10
  }) {
11
11
  let transaction = false;
12
-
13
12
  const tx = cb => {
14
13
  transaction = true;
15
14
  cb();
16
15
  transaction = false;
17
16
  };
18
-
19
17
  const channel = new broadcastChannel.BroadcastChannel(broadcastChannel$1, {
20
18
  webWorkerSupport: false
21
19
  });
@@ -24,7 +22,6 @@
24
22
  if (transaction) {
25
23
  return;
26
24
  }
27
-
28
25
  const {
29
26
  query: {
30
27
  queryHash,
@@ -32,7 +29,6 @@
32
29
  state
33
30
  }
34
31
  } = queryEvent;
35
-
36
32
  if (queryEvent.type === 'updated' && queryEvent.action.type === 'success') {
37
33
  channel.postMessage({
38
34
  type: 'updated',
@@ -41,7 +37,6 @@
41
37
  state
42
38
  });
43
39
  }
44
-
45
40
  if (queryEvent.type === 'removed') {
46
41
  channel.postMessage({
47
42
  type: 'removed',
@@ -50,12 +45,10 @@
50
45
  });
51
46
  }
52
47
  });
53
-
54
48
  channel.onmessage = action => {
55
- if (!(action != null && action.type)) {
49
+ if (!action?.type) {
56
50
  return;
57
51
  }
58
-
59
52
  tx(() => {
60
53
  const {
61
54
  type,
@@ -63,22 +56,18 @@
63
56
  queryKey,
64
57
  state
65
58
  } = action;
66
-
67
59
  if (type === 'updated') {
68
60
  const query = queryCache.get(queryHash);
69
-
70
61
  if (query) {
71
62
  query.setState(state);
72
63
  return;
73
64
  }
74
-
75
65
  queryCache.build(queryClient, {
76
66
  queryKey,
77
67
  queryHash
78
68
  }, state);
79
69
  } else if (type === 'removed') {
80
70
  const query = queryCache.get(queryHash);
81
-
82
71
  if (query) {
83
72
  queryCache.remove(query);
84
73
  }
@@ -89,7 +78,5 @@
89
78
 
90
79
  exports.broadcastQueryClient = broadcastQueryClient;
91
80
 
92
- Object.defineProperty(exports, '__esModule', { value: true });
93
-
94
81
  }));
95
82
  //# sourceMappingURL=index.development.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.development.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":";;;;;;EAQO,SAASA,oBAAT,CAA8B;IACnCC,WADmC;EAEnCC,oBAAAA,kBAAgB,GAAG,gBAAA;EAFgB,CAA9B,EAGyB;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,iCAAJ,CAAqBL,kBAArB,EAAuC;EACrDM,IAAAA,gBAAgB,EAAE,KAAA;EADmC,GAAvC,CAAhB,CAAA;EAIA,EAAA,MAAMC,UAAU,GAAGR,WAAW,CAACS,aAAZ,EAAnB,CAAA;EAEAT,EAAAA,WAAW,CAACS,aAAZ,EAAA,CAA4BC,SAA5B,CAAuCC,UAAD,IAAgB;EACpD,IAAA,IAAIT,WAAJ,EAAiB;EACf,MAAA,OAAA;EACD,KAAA;;MAED,MAAM;EACJU,MAAAA,KAAK,EAAE;UAAEC,SAAF;UAAaC,QAAb;EAAuBC,QAAAA,KAAAA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7B,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
+ {"version":3,"file":"index.development.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":";;;;;;EAQO,SAASA,oBAAoB,CAAC;IACnCC,WAAW;EACXC,oBAAAA,kBAAgB,GAAG,gBAAA;EACQ,CAAC,EAAE;IAC9B,IAAIC,WAAW,GAAG,KAAK,CAAA;IACvB,MAAMC,EAAE,GAAIC,EAAc,IAAK;EAC7BF,IAAAA,WAAW,GAAG,IAAI,CAAA;EAClBE,IAAAA,EAAE,EAAE,CAAA;EACJF,IAAAA,WAAW,GAAG,KAAK,CAAA;KACpB,CAAA;EAED,EAAA,MAAMG,OAAO,GAAG,IAAIC,iCAAgB,CAACL,kBAAgB,EAAE;EACrDM,IAAAA,gBAAgB,EAAE,KAAA;EACpB,GAAC,CAAC,CAAA;EAEF,EAAA,MAAMC,UAAU,GAAGR,WAAW,CAACS,aAAa,EAAE,CAAA;EAE9CT,EAAAA,WAAW,CAACS,aAAa,EAAE,CAACC,SAAS,CAAEC,UAAU,IAAK;EACpD,IAAA,IAAIT,WAAW,EAAE;EACf,MAAA,OAAA;EACF,KAAA;MAEA,MAAM;EACJU,MAAAA,KAAK,EAAE;UAAEC,SAAS;UAAEC,QAAQ;EAAEC,QAAAA,KAAAA;EAAM,OAAA;EACtC,KAAC,GAAGJ,UAAU,CAAA;EAEd,IAAA,IAAIA,UAAU,CAACK,IAAI,KAAK,SAAS,IAAIL,UAAU,CAACM,MAAM,CAACD,IAAI,KAAK,SAAS,EAAE;QACzEX,OAAO,CAACa,WAAW,CAAC;EAClBF,QAAAA,IAAI,EAAE,SAAS;UACfH,SAAS;UACTC,QAAQ;EACRC,QAAAA,KAAAA;EACF,OAAC,CAAC,CAAA;EACJ,KAAA;EAEA,IAAA,IAAIJ,UAAU,CAACK,IAAI,KAAK,SAAS,EAAE;QACjCX,OAAO,CAACa,WAAW,CAAC;EAClBF,QAAAA,IAAI,EAAE,SAAS;UACfH,SAAS;EACTC,QAAAA,QAAAA;EACF,OAAC,CAAC,CAAA;EACJ,KAAA;EACF,GAAC,CAAC,CAAA;EAEFT,EAAAA,OAAO,CAACc,SAAS,GAAIF,MAAM,IAAK;EAC9B,IAAA,IAAI,CAACA,MAAM,EAAED,IAAI,EAAE;EACjB,MAAA,OAAA;EACF,KAAA;EAEAb,IAAAA,EAAE,CAAC,MAAM;QACP,MAAM;UAAEa,IAAI;UAAEH,SAAS;UAAEC,QAAQ;EAAEC,QAAAA,KAAAA;EAAM,OAAC,GAAGE,MAAM,CAAA;QAEnD,IAAID,IAAI,KAAK,SAAS,EAAE;EACtB,QAAA,MAAMJ,KAAK,GAAGJ,UAAU,CAACY,GAAG,CAACP,SAAS,CAAC,CAAA;EAEvC,QAAA,IAAID,KAAK,EAAE;EACTA,UAAAA,KAAK,CAACS,QAAQ,CAACN,KAAK,CAAC,CAAA;EACrB,UAAA,OAAA;EACF,SAAA;EAEAP,QAAAA,UAAU,CAACc,KAAK,CACdtB,WAAW,EACX;YACEc,QAAQ;EACRD,UAAAA,SAAAA;WACD,EACDE,KAAK,CACN,CAAA;EACH,OAAC,MAAM,IAAIC,IAAI,KAAK,SAAS,EAAE;EAC7B,QAAA,MAAMJ,KAAK,GAAGJ,UAAU,CAACY,GAAG,CAACP,SAAS,CAAC,CAAA;EAEvC,QAAA,IAAID,KAAK,EAAE;EACTJ,UAAAA,UAAU,CAACe,MAAM,CAACX,KAAK,CAAC,CAAA;EAC1B,SAAA;EACF,OAAA;EACF,KAAC,CAAC,CAAA;KACH,CAAA;EACH;;;;;;;;"}
@@ -1,2 +1,2 @@
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"}){let r=!1;const a=new t.BroadcastChannel(s,{webWorkerSupport:!1}),n=e.getQueryCache();e.getQueryCache().subscribe((e=>{if(r)return;const{query:{queryHash:t,queryKey:s,state:n}}=e;"updated"===e.type&&"success"===e.action.type&&a.postMessage({type:"updated",queryHash:t,queryKey:s,state:n}),"removed"===e.type&&a.postMessage({type:"removed",queryHash:t,queryKey:s})})),a.onmessage=t=>{null!=t&&t.type&&(r=!0,(()=>{const{type:s,queryHash:r,queryKey:a,state:o}=t;if("updated"===s){const t=n.get(r);if(t)return void t.setState(o);n.build(e,{queryKey:a,queryHash:r},o)}else if("removed"===s){const e=n.get(r);e&&n.remove(e)}})(),r=!1)}},Object.defineProperty(e,"__esModule",{value:!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"}){let a=!1;const r=new t.BroadcastChannel(s,{webWorkerSupport:!1}),n=e.getQueryCache();e.getQueryCache().subscribe((e=>{if(a)return;const{query:{queryHash:t,queryKey:s,state:n}}=e;"updated"===e.type&&"success"===e.action.type&&r.postMessage({type:"updated",queryHash:t,queryKey:s,state:n}),"removed"===e.type&&r.postMessage({type:"removed",queryHash:t,queryKey:s})})),r.onmessage=t=>{t?.type&&(a=!0,(()=>{const{type:s,queryHash:a,queryKey:r,state:o}=t;if("updated"===s){const t=n.get(a);if(t)return void t.setState(o);n.build(e,{queryKey:r,queryHash:a},o)}else if("removed"===s){const e=n.get(a);e&&n.remove(e)}})(),a=!1)}}}));
2
2
  //# sourceMappingURL=index.production.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.production.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":["queryClient","broadcastChannel","transaction","channel","BroadcastChannel","webWorkerSupport","queryCache","getQueryCache","subscribe","queryEvent","query","queryHash","queryKey","state","type","action","postMessage","onmessage","get","setState","build","remove","cb"],"mappings":"yVAQO,UAA8BA,YACnCA,EACAC,iBAAAA,EAAmB,mBAEnB,IAAIC,GAAc,EAClB,MAMMC,EAAU,IAAIC,EAAJA,iBAAqBH,EAAkB,CACrDI,kBAAkB,IAGdC,EAAaN,EAAYO,gBAE/BP,EAAYO,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,OAvCbZ,GAAc,EA2CX,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,MACTpB,EACA,CACEY,WACAD,aAEFE,QAEG,GAAa,YAATC,EAAoB,CAC7B,MAAMJ,EAAQJ,EAAWY,IAAIP,GAEzBD,GACFJ,EAAWe,OAAOX,KAjExBY,GACApB,GAAc"}
1
+ {"version":3,"file":"index.production.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":["queryClient","broadcastChannel","transaction","channel","BroadcastChannel","webWorkerSupport","queryCache","getQueryCache","subscribe","queryEvent","query","queryHash","queryKey","state","type","action","postMessage","onmessage","get","setState","build","remove","cb"],"mappings":"yVAQO,UAA8BA,YACnCA,EACAC,iBAAAA,EAAmB,mBAEnB,IAAIC,GAAc,EAClB,MAMMC,EAAU,IAAIC,EAAgBA,iBAACH,EAAkB,CACrDI,kBAAkB,IAGdC,EAAaN,EAAYO,gBAE/BP,EAAYO,gBAAgBC,WAAWC,IACrC,GAAIP,EACF,OAGF,MACEQ,OAAOC,UAAEA,EAASC,SAAEA,EAAQC,MAAEA,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,IACdA,GAAQD,OAvCbZ,GAAc,EA2CX,MACD,MAAMY,KAAEA,EAAIH,UAAEA,EAASC,SAAEA,EAAQC,MAAEA,GAAUE,EAE7C,GAAa,YAATD,EAAoB,CACtB,MAAMJ,EAAQJ,EAAWY,IAAIP,GAE7B,GAAID,EAEF,YADAA,EAAMS,SAASN,GAIjBP,EAAWc,MACTpB,EACA,CACEY,WACAD,aAEFE,QAEG,GAAa,YAATC,EAAoB,CAC7B,MAAMJ,EAAQJ,EAAWY,IAAIP,GAEzBD,GACFJ,EAAWe,OAAOX,KAjExBY,GACApB,GAAc"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-broadcast-client-experimental",
3
- "version": "4.24.10",
3
+ "version": "5.0.0-alpha.1",
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",
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "dependencies": {
31
31
  "broadcast-channel": "^4.14.0",
32
- "@tanstack/query-core": "4.24.10"
32
+ "@tanstack/query-core": "5.0.0-alpha.1"
33
33
  },
34
34
  "scripts": {
35
35
  "clean": "rimraf ./build",