Skip to content

fix: make broadcast-channel optional #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions docs/src/pages/plugins/broadcastQueryClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ title: broadcastQueryClient (Experimental)

This utility comes packaged with `svelte-query` and is available under the `@sveltestack/svelte-query` import.

However, this utility needs the `broadcast-channel` dependency to be available but it's not provided by this package.

So if you want to use this utility, you need to install it in your project:

```bash
# using npm:
npm install broadcast-channel

# using yarn:
yarn add broadcast-channel

# using pnpm:
pnpm add broadcast-channel
```

## Usage

Import the `broadcastQueryClient` function, and pass it your `QueryClient` instance, and optionally, set a `broadcastChannel`.
Expand All @@ -20,10 +35,12 @@ import { broadcastQueryClient } from '@sveltestack/svelte-query'

const queryClient = new QueryClient()

broadcastQueryClient({
queryClient,
broadcastChannel: 'my-app',
})
onMount(async () => {
await broadcastQueryClient({
queryClient,
broadcastChannel: 'my-app',
})
});
```

## API
Expand All @@ -33,7 +50,7 @@ broadcastQueryClient({
Pass this function a `QueryClient` instance and optionally, a `broadcastChannel`.

```ts
broadcastQueryClient({ queryClient, broadcastChannel })
await broadcastQueryClient({ queryClient, broadcastChannel })
```

### `Options`
Expand Down
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"build": "rimraf ./dist && rollup -c && yarn build:types && yarn build:lib && yarn build:svelte && yarn build:svelte-types",
"build:types": "tsc --project ./tsconfig.types.json && replace 'import type' 'import' ./dist -r --silent && replace 'export type' 'export' ./dist -r --silent",
"build:lib": "rimraf ./lib && tsc --project tsconfig.lib.json --module 'CommonJS' --outDir ./lib",
"build:svelte": "rimraf ./svelte && tsc --project tsconfig.lib.json --module 'es2015' --outDir ./svelte && node scripts/svelte-copy.js",
"build:svelte": "rimraf ./svelte && tsc --project tsconfig.lib.json --module 'es2020' --outDir ./svelte && node scripts/svelte-copy.js",
"build:svelte-types": "node scripts/svelte-dts.js",
"prepublishOnly": "yarn run build",
"test:watch": "yarn test -- --watch",
Expand Down Expand Up @@ -50,6 +50,7 @@
"axios": "^0.21.1",
"babel-jest": "^25.2.6",
"babel-loader": "^8.1.0",
"broadcast-channel": "^4.5.0",
"cross-env": "^7.0.2",
"del-cli": "^3.0.0",
"eslint": "7.x",
Expand Down Expand Up @@ -84,13 +85,18 @@
"type-fest": "^0.21.1",
"typescript": "^4.0.3"
},
"peerDependencies": {
"broadcast-channel": "^4.5.0"
},
"peerDependenciesMeta": {
"broadcast-channel": {
"optional": true
}
},
"keywords": [
"svelte",
"react-query"
],
"dependencies": {
"broadcast-channel": "^4.2.0"
},
"husky": {
"hooks": {
"pre-commit": "yarn test:ci"
Expand Down
5 changes: 3 additions & 2 deletions src/queryCore/broadcastQueryClient-experimental/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { BroadcastChannel } from 'broadcast-channel'
import { QueryClient } from '../core'

interface BroadcastQueryClientOptions {
queryClient: QueryClient
broadcastChannel: string
}

export function broadcastQueryClient({
export async function broadcastQueryClient({
queryClient,
broadcastChannel = 'svelte-query',
}: BroadcastQueryClientOptions) {
const { BroadcastChannel } = await import('broadcast-channel')

let transaction = false
const tx = (cb: () => void) => {
transaction = true
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "@tsconfig/svelte/tsconfig.json",
"compilerOptions": {
"module": "ES2020",
"lib": ["dom", "ESNext", "es2018.promise"],
"sourceMap": true,
"importsNotUsedAsValues": "preserve"
Expand Down
53 changes: 27 additions & 26 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -821,13 +821,20 @@
core-js-pure "^3.0.0"
regenerator-runtime "^0.13.4"

"@babel/runtime@^7.10.2", "@babel/runtime@^7.12.5", "@babel/runtime@^7.6.2", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2":
"@babel/runtime@^7.10.2", "@babel/runtime@^7.12.5", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2":
version "7.13.10"
resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.13.10.tgz"
integrity sha512-4QPkjJq6Ns3V/RgpEahRk+AGfL0eO6RHHtTWoNNr5mO49G6B5+X6d6THgWEAvTrznU5xYpbAlVKRYcsCgh/Akw==
dependencies:
regenerator-runtime "^0.13.4"

"@babel/runtime@^7.16.0", "@babel/runtime@^7.6.2":
version "7.16.3"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.16.3.tgz#b86f0db02a04187a3c17caa77de69840165d42d5"
integrity sha512-WBwekcqacdY2e9AF/Q7WLFUWmdJGJTkbjqTjoMDgXkVZ3ZRUvOPsLb5KdwISoQVsbP+DQzVZW4Zhci0DvpbNTQ==
dependencies:
regenerator-runtime "^0.13.4"

"@babel/template@^7.10.4", "@babel/template@^7.12.7", "@babel/template@^7.3.3":
version "7.12.7"
resolved "https://registry.npmjs.org/@babel/template/-/template-7.12.7.tgz"
Expand Down Expand Up @@ -1845,9 +1852,9 @@ bcrypt-pbkdf@^1.0.0:
tweetnacl "^0.14.3"

big-integer@^1.6.16:
version "1.6.48"
resolved "https://registry.npmjs.org/big-integer/-/big-integer-1.6.48.tgz"
integrity sha512-j51egjPa7/i+RdiRuJbPdJ2FIUYYPhvYLjzoYbcMMm62ooO6F94fETG4MTs46zPAF9Brs04OajboA/qTGuz78w==
version "1.6.51"
resolved "https://registry.yarnpkg.com/big-integer/-/big-integer-1.6.51.tgz#0df92a5d9880560d3ff2d5fd20245c889d130686"
integrity sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==

big.js@^5.2.2:
version "5.2.2"
Expand Down Expand Up @@ -1890,19 +1897,18 @@ braces@^3.0.1, braces@~3.0.2:
dependencies:
fill-range "^7.0.1"

broadcast-channel@^4.2.0:
version "4.2.0"
resolved "https://registry.npmjs.org/broadcast-channel/-/broadcast-channel-4.2.0.tgz"
integrity sha512-XX9yNnIy/v2T+HR5EKIH7ziM2mYTefsrzZ2lkCmFZxwCDG7Ns7HLIooUXA114sCeFRJ4MEXEgdMapxfPDh9Xkg==
broadcast-channel@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/broadcast-channel/-/broadcast-channel-4.5.0.tgz#d4717c493e219908fcb7f2f9078fe0baf95b77c1"
integrity sha512-jp+VPlQ1HyR0CM3uIYUrdpXupBvhTMFRkjR6mEmt5W4HaGDPFEzrO2Jqvi2PZ6zCC4zwLeco7CC5EUJPrVH8Tw==
dependencies:
"@babel/runtime" "^7.7.2"
"@babel/runtime" "^7.16.0"
detect-node "^2.1.0"
js-sha3 "0.8.0"
microseconds "0.2.0"
nano-time "1.0.0"
oblivious-set "1.0.0"
rimraf "3.0.2"
unload "2.2.0"
unload "2.3.1"

browser-process-hrtime@^1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -2422,9 +2428,9 @@ detect-newline@^3.0.0:
resolved "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz"
integrity sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA==

detect-node@^2.0.4, detect-node@^2.1.0:
detect-node@2.1.0, detect-node@^2.1.0:
version "2.1.0"
resolved "https://registry.npmjs.org/detect-node/-/detect-node-2.1.0.tgz"
resolved "https://registry.yarnpkg.com/detect-node/-/detect-node-2.1.0.tgz#c9c70775a49c3d03bc2c06d9a73be550f978f8b1"
integrity sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==

diff-sequences@^26.6.2:
Expand Down Expand Up @@ -4141,11 +4147,6 @@ jest@^26.6.3:
import-local "^3.0.2"
jest-cli "^26.6.3"

[email protected]:
version "0.8.0"
resolved "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz"
integrity sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==

js-tokens@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz"
Expand Down Expand Up @@ -4472,7 +4473,7 @@ micromatch@^4.0.2:

[email protected]:
version "0.2.0"
resolved "https://registry.npmjs.org/microseconds/-/microseconds-0.2.0.tgz"
resolved "https://registry.yarnpkg.com/microseconds/-/microseconds-0.2.0.tgz#233b25f50c62a65d861f978a4a4f8ec18797dc39"
integrity sha512-n7DHHMjR1avBbSpsTBj6fmMGh2AGrifVV4e+WYc3Q9lO+xnSZ3NyhcBND3vzzatt05LFhoKFRxrIyklmLlUtyA==

[email protected]:
Expand Down Expand Up @@ -4548,7 +4549,7 @@ nan@^2.14.1:

[email protected]:
version "1.0.0"
resolved "https://registry.npmjs.org/nano-time/-/nano-time-1.0.0.tgz"
resolved "https://registry.yarnpkg.com/nano-time/-/nano-time-1.0.0.tgz#b0554f69ad89e22d0907f7a12b0993a5d96137ef"
integrity sha1-sFVPaa2J4i0JB/ehKwmTpdlhN+8=
dependencies:
big-integer "^1.6.16"
Expand Down Expand Up @@ -4721,7 +4722,7 @@ object.values@^1.1.1:

[email protected]:
version "1.0.0"
resolved "https://registry.npmjs.org/oblivious-set/-/oblivious-set-1.0.0.tgz"
resolved "https://registry.yarnpkg.com/oblivious-set/-/oblivious-set-1.0.0.tgz#c8316f2c2fb6ff7b11b6158db3234c49f733c566"
integrity sha512-z+pI07qxo4c2CulUHCDf9lcqDlMSo72N/4rLUpRXf6fu+q8vjt8y0xS+Tlf8NTJDdTXHbdeO1n3MlbctwEoXZw==

once@^1.3.0, once@^1.3.1, once@^1.4.0:
Expand Down Expand Up @@ -6103,13 +6104,13 @@ universalify@^0.1.2:
resolved "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz"
integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==

unload@2.2.0:
version "2.2.0"
resolved "https://registry.npmjs.org/unload/-/unload-2.2.0.tgz"
integrity sha512-B60uB5TNBLtN6/LsgAf3udH9saB5p7gqJwcFfbOEZ8BcBHnGwCf6G/TGiEqkRAxX7zAFIUtzdrXQSdL3Q/wqNA==
unload@2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/unload/-/unload-2.3.1.tgz#9d16862d372a5ce5cb630ad1309c2fd6e35dacfe"
integrity sha512-MUZEiDqvAN9AIDRbbBnVYVvfcR6DrjCqeU2YQMmliFZl9uaBUjTkhuDQkBiyAy8ad5bx1TXVbqZ3gg7namsWjA==
dependencies:
"@babel/runtime" "^7.6.2"
detect-node "^2.0.4"
detect-node "2.1.0"

unset-value@^1.0.0:
version "1.0.0"
Expand Down