@tanstack/query-broadcast-client-experimental 5.0.0-alpha.61 → 5.0.0-alpha.63
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.
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var broadcastChannel = require('broadcast-channel');
|
|
4
|
+
|
|
5
|
+
function broadcastQueryClient({
|
|
6
|
+
queryClient,
|
|
7
|
+
broadcastChannel: broadcastChannel$1 = 'tanstack-query'
|
|
8
|
+
}) {
|
|
9
|
+
let transaction = false;
|
|
10
|
+
const tx = cb => {
|
|
11
|
+
transaction = true;
|
|
12
|
+
cb();
|
|
13
|
+
transaction = false;
|
|
14
|
+
};
|
|
15
|
+
const channel = new broadcastChannel.BroadcastChannel(broadcastChannel$1, {
|
|
16
|
+
webWorkerSupport: false
|
|
17
|
+
});
|
|
18
|
+
const queryCache = queryClient.getQueryCache();
|
|
19
|
+
queryClient.getQueryCache().subscribe(queryEvent => {
|
|
20
|
+
if (transaction) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const {
|
|
24
|
+
query: {
|
|
25
|
+
queryHash,
|
|
26
|
+
queryKey,
|
|
27
|
+
state
|
|
28
|
+
}
|
|
29
|
+
} = queryEvent;
|
|
30
|
+
if (queryEvent.type === 'updated' && queryEvent.action.type === 'success') {
|
|
31
|
+
channel.postMessage({
|
|
32
|
+
type: 'updated',
|
|
33
|
+
queryHash,
|
|
34
|
+
queryKey,
|
|
35
|
+
state
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (queryEvent.type === 'removed') {
|
|
39
|
+
channel.postMessage({
|
|
40
|
+
type: 'removed',
|
|
41
|
+
queryHash,
|
|
42
|
+
queryKey
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
channel.onmessage = action => {
|
|
47
|
+
if (!(action != null && action.type)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
tx(() => {
|
|
51
|
+
const {
|
|
52
|
+
type,
|
|
53
|
+
queryHash,
|
|
54
|
+
queryKey,
|
|
55
|
+
state
|
|
56
|
+
} = action;
|
|
57
|
+
if (type === 'updated') {
|
|
58
|
+
const query = queryCache.get(queryHash);
|
|
59
|
+
if (query) {
|
|
60
|
+
query.setState(state);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
queryCache.build(queryClient, {
|
|
64
|
+
queryKey,
|
|
65
|
+
queryHash
|
|
66
|
+
}, state);
|
|
67
|
+
} else if (type === 'removed') {
|
|
68
|
+
const query = queryCache.get(queryHash);
|
|
69
|
+
if (query) {
|
|
70
|
+
queryCache.remove(query);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
exports.broadcastQueryClient = broadcastQueryClient;
|
|
78
|
+
//# sourceMappingURL=index.legacy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.legacy.cjs","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,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EAAE;AACTJ,UAAAA,UAAU,CAACe,MAAM,CAACX,KAAK,CAAC,CAAA;AAC1B,SAAA;AACF,OAAA;AACF,KAAC,CAAC,CAAA;GACH,CAAA;AACH;;;;"}
|
|
@@ -0,0 +1,76 @@
|
|
|
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.legacy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.legacy.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,SAA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ACF,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.
|
|
3
|
+
"version": "5.0.0-alpha.63",
|
|
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",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
},
|
|
13
13
|
"type": "module",
|
|
14
14
|
"types": "build/lib/index.d.ts",
|
|
15
|
-
"main": "build/lib/index.cjs",
|
|
16
|
-
"module": "build/lib/index.js",
|
|
15
|
+
"main": "build/lib/index.legacy.cjs",
|
|
16
|
+
"module": "build/lib/index.legacy.js",
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
19
|
"types": "./build/lib/index.d.ts",
|