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

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.
@@ -44,7 +44,7 @@ function broadcastQueryClient({
44
44
  }
45
45
  });
46
46
  channel.onmessage = action => {
47
- if (!(action != null && action.type)) {
47
+ if (!action?.type) {
48
48
  return;
49
49
  }
50
50
  tx(() => {
@@ -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,oBAAoBA,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;AAED,EAAA,MAAMG,OAAO,GAAG,IAAIC,iCAAgB,CAACL,kBAAgB,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,IAAI,EAAE,SAAS;QACfH,SAAS;AACTC,QAAAA,QAAAA;AACF,OAAC,CAAC,CAAA;AACJ,KAAA;AACF,GAAC,CAAC,CAAA;AAEFT,EAAAA,OAAO,CAACc,SAAS,GAAIF,MAAM,IAAK;AAC9B,IAAA,IAAI,EAACA,MAAM,IAAA,IAAA,IAANA,MAAM,CAAED,IAAI,CAAE,EAAA;AACjB,MAAA,OAAA;AACF,KAAA;AAEAb,IAAAA,EAAE,CAAC,MAAM;MACP,MAAM;QAAEa,IAAI;QAAEH,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,KACF,CAAC,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;;;;"}
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,oBAAoBA,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;AAED,EAAA,MAAMG,OAAO,GAAG,IAAIC,iCAAgB,CAACL,kBAAgB,EAAE;AACrDM,IAAAA,gBAAg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,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,KACF,CAAC,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;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-broadcast-client-experimental",
3
- "version": "5.0.0-alpha.49",
3
+ "version": "5.0.0-alpha.50",
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",
@@ -25,7 +25,6 @@
25
25
  "sideEffects": false,
26
26
  "files": [
27
27
  "build/lib/*",
28
- "build/umd/*",
29
28
  "src"
30
29
  ],
31
30
  "dependencies": {
@@ -1,82 +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
- }) {
11
- let transaction = false;
12
- const tx = cb => {
13
- transaction = true;
14
- cb();
15
- transaction = false;
16
- };
17
- const channel = new broadcastChannel.BroadcastChannel(broadcastChannel$1, {
18
- webWorkerSupport: false
19
- });
20
- const queryCache = queryClient.getQueryCache();
21
- queryClient.getQueryCache().subscribe(queryEvent => {
22
- if (transaction) {
23
- return;
24
- }
25
- const {
26
- query: {
27
- queryHash,
28
- queryKey,
29
- state
30
- }
31
- } = queryEvent;
32
- if (queryEvent.type === 'updated' && queryEvent.action.type === 'success') {
33
- channel.postMessage({
34
- type: 'updated',
35
- queryHash,
36
- queryKey,
37
- state
38
- });
39
- }
40
- if (queryEvent.type === 'removed') {
41
- channel.postMessage({
42
- type: 'removed',
43
- queryHash,
44
- queryKey
45
- });
46
- }
47
- });
48
- channel.onmessage = action => {
49
- if (!action?.type) {
50
- return;
51
- }
52
- tx(() => {
53
- const {
54
- type,
55
- queryHash,
56
- queryKey,
57
- state
58
- } = action;
59
- if (type === 'updated') {
60
- const query = queryCache.get(queryHash);
61
- if (query) {
62
- query.setState(state);
63
- return;
64
- }
65
- queryCache.build(queryClient, {
66
- queryKey,
67
- queryHash
68
- }, state);
69
- } else if (type === 'removed') {
70
- const query = queryCache.get(queryHash);
71
- if (query) {
72
- queryCache.remove(query);
73
- }
74
- }
75
- });
76
- };
77
- }
78
-
79
- exports.broadcastQueryClient = broadcastQueryClient;
80
-
81
- }));
82
- //# 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 { 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,oBAAoBA,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;IAE9CT,WAAW,CAACS,aAAa,EAAE,CAACC,SAAS,CAAEC,UAAU,IAAK;EACpD,IAAA,IAAIT,WAAW,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A;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 +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"}){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
- //# 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 { 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,YAEJ,IAGFT,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,EAEJ,MAAO,GAAa,YAATC,EAAoB,CAC7B,MAAMJ,EAAQJ,EAAWY,IAAIP,GAEzBD,GACFJ,EAAWe,OAAOX,EAEtB,GAnEFY,GACApB,GAAc,EAmEZ,CAEN"}