Skip to content
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

1.5.1 #151

Merged
merged 140 commits into from
Mar 7, 2024
Merged

1.5.1 #151

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
7aca013
feat: QweryProvider (#1)
nmathew98 Feb 22, 2024
f573b45
feat: useQwery hook (#2)
nmathew98 Feb 22, 2024
454ac45
chore: update readme (#3)
nmathew98 Feb 22, 2024
a64a494
feat: subscriptions and polling (#4)
nmathew98 Feb 22, 2024
edbcb4c
feat: useRememberScroll (#5)
nmathew98 Feb 22, 2024
838dade
feat: refetchOnWindowFocus (#6)
nmathew98 Feb 22, 2024
6308e40
0.0.1
nmathew98 Feb 22, 2024
39b2ae6
fix: awaiting initial value, either or can resolve to nullish (#8)
nmathew98 Feb 22, 2024
81747cc
types: useQweryOptions (#9)
nmathew98 Feb 23, 2024
ba5f287
chore: add vitest, react testing library, jsdom (#10)
nmathew98 Feb 23, 2024
4fe7750
test: adding test api and redis (#11)
nmathew98 Feb 23, 2024
05ff145
test: add tests for useQwery, csr and ssr (#12)
nmathew98 Feb 23, 2024
ca97419
0.0.2
nmathew98 Feb 23, 2024
e05c495
chore: cleanup and update vite to build as lib (#14)
nmathew98 Feb 23, 2024
6478c65
chore: remove api.put (#15)
nmathew98 Feb 23, 2024
ad08c91
chore: update deps, update exports, update types (#16)
nmathew98 Feb 23, 2024
3aacb02
fix: effects don't run in ssr (#17)
nmathew98 Feb 23, 2024
77f4f7c
fix: silence act errors (#18)
nmathew98 Feb 23, 2024
58e822b
style: remove unused imports (#19)
nmathew98 Feb 23, 2024
15116cc
0.0.3
nmathew98 Feb 23, 2024
8fe095e
chore: update readme (#21)
nmathew98 Feb 23, 2024
725bdcd
chore: update readme (#22)
nmathew98 Feb 23, 2024
fcfb63c
1.0.0
nmathew98 Feb 23, 2024
e58f015
chore: update export locations (#24)
nmathew98 Feb 23, 2024
534f7b8
1.0.1
nmathew98 Feb 23, 2024
edba570
chore: update README (#26)
nmathew98 Feb 23, 2024
5728012
1.0.2
nmathew98 Feb 23, 2024
ed709a7
chore: update readme (#28)
nmathew98 Feb 25, 2024
09e2603
chore: update exports (#29)
nmathew98 Feb 25, 2024
866ff1d
1.0.3
nmathew98 Feb 25, 2024
84b099f
fix: unsubscribe (#31)
nmathew98 Feb 25, 2024
eb3127e
fix: subscription return (#32)
nmathew98 Feb 25, 2024
099a3eb
1.0.4
nmathew98 Feb 25, 2024
c7eb02f
fix: fix build output issues making react and other deps external, up…
nmathew98 Feb 25, 2024
5f20ac0
1.0.5
nmathew98 Feb 25, 2024
d815348
feat: to disable queries if offline (#36)
nmathew98 Feb 28, 2024
3642d32
1.0.6
nmathew98 Feb 28, 2024
bee5a80
feat: add broadcast channel support (#38)
nmathew98 Feb 28, 2024
1d6072c
1.1.0
nmathew98 Feb 28, 2024
ac84628
feat: cancellable queries (#40)
nmathew98 Feb 28, 2024
965b290
chore: update readme (#42)
nmathew98 Feb 28, 2024
2ee995e
1.2.0
nmathew98 Feb 28, 2024
a10158b
feat: suspense (#45)
nmathew98 Feb 29, 2024
26d76d6
1.3.0
nmathew98 Feb 29, 2024
5d68c6f
fix: suspense throw errors (#53)
nmathew98 Feb 29, 2024
65547d1
1.3.1
nmathew98 Feb 29, 2024
a1c7358
fix: suspense onChange, throw errors after invoking onError (#55)
nmathew98 Mar 1, 2024
cdb93c9
chore: monorepo (#56)
nmathew98 Mar 1, 2024
13dd8b6
chore: run lint, test and build concurrently (#57)
nmathew98 Mar 1, 2024
0961b46
feat: remove ability to manually handle broadcasts (#58)
nmathew98 Mar 1, 2024
96ebd2f
v1.3.2
nmathew98 Mar 1, 2024
64333a3
fix: trigger rerender after dispatching a broadcasted update (#60)
nmathew98 Mar 1, 2024
7e28505
fix: close broadcast channel (#61)
nmathew98 Mar 1, 2024
815037e
fix: early return if broadcast next is same as current (#62)
nmathew98 Mar 1, 2024
44c243d
fix: stablize id for each broadcaster, update some types, add pack sc…
nmathew98 Mar 1, 2024
7d15c26
v1.3.3
nmathew98 Mar 1, 2024
08e24c7
refactor: rework types (#65)
nmathew98 Mar 2, 2024
2c4220d
refactor: reducing use of any (#66)
nmathew98 Mar 2, 2024
0cd58b9
chore: update package.json (#67)
nmathew98 Mar 2, 2024
dab10f2
refactor: using any instead of unknown, less errors for no reason (#68)
nmathew98 Mar 2, 2024
d3e4c07
v1.4.0
nmathew98 Mar 2, 2024
6a1a5f7
chore(vue): vue init (#70)
nmathew98 Mar 2, 2024
b8b0233
feat(vue): useExecutionEnvironment (#71)
nmathew98 Mar 2, 2024
3107f48
feat(vue): use network mode (#72)
nmathew98 Mar 2, 2024
42d905b
fix(vue): run a fetch on mounted also when determining network status…
nmathew98 Mar 2, 2024
bc0d2a7
feat(vue): use remember scroll (#74)
nmathew98 Mar 2, 2024
0dba99e
feat(vue): qwery context (#75)
nmathew98 Mar 2, 2024
aa0b576
feat(vue): use qwery (#76)
nmathew98 Mar 2, 2024
e8c1217
chore(vue): update exports (#77)
nmathew98 Mar 2, 2024
6100f77
fix(vue): health check initially even for ssr (#78)
nmathew98 Mar 2, 2024
91ac076
fix(vue): check hasInjectionContext (#79)
nmathew98 Mar 2, 2024
4af9f64
refactor(vue): add use id composable (#80)
nmathew98 Mar 2, 2024
d69b26e
Revert "refactor(vue): add use id composable (#80)" (#82)
nmathew98 Mar 2, 2024
4f87df8
chore(vue): add api and redis from react, add example test (#83)
nmathew98 Mar 2, 2024
0daa36d
test(vue): csr (#84)
nmathew98 Mar 2, 2024
b05f725
test(vue): ssr (#85)
nmathew98 Mar 2, 2024
b31f3da
refactor(vue): normal args instead of object (#86)
nmathew98 Mar 2, 2024
ad38f71
test(vue): refactor, going with defineComponent (#87)
nmathew98 Mar 2, 2024
9a633f5
refactor(react): initializeCrdt -> initializeCRDT, remove refetch (#88)
nmathew98 Mar 2, 2024
ea71d91
refactor(vue): remove refetch (#89)
nmathew98 Mar 2, 2024
3db17e1
chore(react,vue): update clean script (#90)
nmathew98 Mar 2, 2024
5c00884
chore: update readme (#91)
nmathew98 Mar 2, 2024
e912334
v1.4.1
nmathew98 Mar 2, 2024
3b95975
types(react,vue): improve BaseQueryOptions (#94)
nmathew98 Mar 2, 2024
ae850f1
fix(vue): make dispatch a getter instead of a computed ref, cleaner u…
nmathew98 Mar 2, 2024
3e514e0
chore(react,vue): update readme (#95)
nmathew98 Mar 2, 2024
60fa805
v1.4.2
nmathew98 Mar 2, 2024
2494a67
chore(react,vue): use shared types (#97)
nmathew98 Mar 3, 2024
fc69843
fix(vue,react): cache fetched initial value (#98)
nmathew98 Mar 3, 2024
7f5a829
chore: update readme (#99)
nmathew98 Mar 3, 2024
98b555a
fix(vue,react): update cache on refetch (#100)
nmathew98 Mar 3, 2024
e067160
chore: update deps (#101)
nmathew98 Mar 3, 2024
b534014
v1.4.3
nmathew98 Mar 3, 2024
76faae3
chore(react,vue): update main entry point (#104)
nmathew98 Mar 3, 2024
e62dd7d
chore(svelte): svelte init (#103)
nmathew98 Mar 3, 2024
44503b4
chore: update gh actions (#105)
nmathew98 Mar 3, 2024
f027319
chore: pnpm lerna run instead of pnpx (#106)
nmathew98 Mar 3, 2024
299dea1
types(vue,react): improve typing for UseQweryReturn (#107)
nmathew98 Mar 3, 2024
868db25
chore(vue): tsx -> ts (#108)
nmathew98 Mar 3, 2024
347d44f
chore(react,vue,svelte): make qwery-shared a dev dep (#109)
nmathew98 Mar 3, 2024
42604d3
v1.4.4
nmathew98 Mar 3, 2024
047e177
feat(svelte): useExecutionEnvironment (#113)
nmathew98 Mar 4, 2024
129aa42
feat(svelte): context (#114)
nmathew98 Mar 4, 2024
232927e
feat(svelte): useNetworkMode (#115)
nmathew98 Mar 4, 2024
d56d05f
feat(svelte): useRememberScroll (#116)
nmathew98 Mar 4, 2024
f4e67fc
chore(svelte): update exports (#117)
nmathew98 Mar 4, 2024
cff2410
feat(svelte): useQwery (#118)
nmathew98 Mar 4, 2024
f870c2a
chore(react,vue): update tsconfig (#119)
nmathew98 Mar 4, 2024
90b3e0a
types(react): type import UseNetworkModeOptions (#120)
nmathew98 Mar 4, 2024
2d90d89
refactor(vue,svelte): computeInitialValueTest -> computeInitialValue …
nmathew98 Mar 4, 2024
fab1548
refactor(react,vue,svelte): move no op cache to shared (#122)
nmathew98 Mar 4, 2024
49c6fda
fix(svelte): for dispatch move subscribe out of getter (#123)
nmathew98 Mar 4, 2024
06d8689
chore: update readme (#124)
nmathew98 Mar 4, 2024
a8a843f
feat: add map reduce and maybe return a promise utility fn for change…
nmathew98 Mar 5, 2024
7951b68
chore: update readme (#126)
nmathew98 Mar 6, 2024
58be5b1
refactor(shared): update mapReduceMaybePromise to be rest args instea…
nmathew98 Mar 6, 2024
4ead1a3
feat(react,svelte,vue): useMonitoredFetch hook (#128)
nmathew98 Mar 6, 2024
0bc807a
fix(react,vue,svelte): allow specifying other options (#129)
nmathew98 Mar 6, 2024
7962bdc
types(react,vue,svelte): adding types (#130)
nmathew98 Mar 6, 2024
44b3ddf
chore(svelte): update build config (#131)
nmathew98 Mar 6, 2024
bf7c005
chore: update readme (#132)
nmathew98 Mar 6, 2024
507f6e2
chore(svelte): update package.json (#133)
nmathew98 Mar 6, 2024
4f1a439
v1.5.0
nmathew98 Mar 6, 2024
d8591c5
chore(react,vue,svelte): update readme with more accurate figures (#135)
nmathew98 Mar 7, 2024
1e6b47c
chore(solid): solid start (#136)
nmathew98 Mar 7, 2024
fae9f26
chore(react,vue,svelte,solid): update readme (#137)
nmathew98 Mar 7, 2024
54eefef
feat(solid): useMonitoredFetch (#138)
nmathew98 Mar 7, 2024
f2a0280
feat(solid): useExecutionEnvironment (#139)
nmathew98 Mar 7, 2024
320e8b7
feat(solid): useRememberScroll (#140)
nmathew98 Mar 7, 2024
4ed90e4
feat(solid): useNetworkMode (#141)
nmathew98 Mar 7, 2024
43d5065
fix(solid): useMonitoredFetch (#142)
nmathew98 Mar 7, 2024
46eb237
feat(solid): context (#143)
nmathew98 Mar 7, 2024
d146b84
chore(solid): update exports (#144)
nmathew98 Mar 7, 2024
2afa899
fix(solid): not destructuring props (#145)
nmathew98 Mar 7, 2024
ff3cbaf
fix(solid): onCleanup (#146)
nmathew98 Mar 7, 2024
b643958
feat(solid): useQwery (#147)
nmathew98 Mar 7, 2024
cf3e0c4
types(solid): update useQwery types (#148)
nmathew98 Mar 7, 2024
76dc682
chore(solid): update readme (#150)
nmathew98 Mar 7, 2024
695726c
v1.5.1
nmathew98 Mar 7, 2024
362dc47
Merge branch 'master' of https://github.com/nmathew98/qwery into chor…
nmathew98 Mar 7, 2024
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

Asynchronous state management made simple.

Most of the use cases of [TanStack Query](https://tanstack.com/query/latest/) are covered with a similar API, TanStack Query comes in at most ~2 MB while Qwery comes in at most ~220 kB.
Most of the use cases of [TanStack Query](https://tanstack.com/query/latest/) are covered with a similar API while being 60% lighter.

Documentation: [Wiki](https://github.com/nmathew98/qwery/wiki/1.-Introduction)

## Frameworks

- React ✅
- Vue ✅
- Svelte ✅
- Solid ✅

## Features

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "1.5.0",
"version": "1.5.1",
"packages": [
"packages/*"
],
Expand Down
6 changes: 5 additions & 1 deletion packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

Asynchronous state management in React made simple.

Most of the use cases of [React Query](https://tanstack.com/query/latest/) are covered with a similar API, React Query comes in at ~2 MB while React Qwery comes in at ~220 kB.
Most of the use cases of [React Query](https://tanstack.com/query/latest/) are covered with a similar API while being 65% lighter.

React Query bundle size: [56.6 kB minified](https://bundlephobia.com/package/@tanstack/react-query)

React Qwery bundle size: [19.7 kB minified](https://bundlephobia.com/package/@b.s/react-qwery)

Documentation: [Wiki](https://github.com/nmathew98/qwery/wiki/1.-Introduction)

Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@b.s/react-qwery",
"version": "1.5.0",
"version": "1.5.1",
"type": "module",
"repository": {
"type": "git",
Expand Down
21 changes: 21 additions & 0 deletions packages/solid/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
ignorePatterns: ["dist", ".eslintrc.cjs"],
parser: "@typescript-eslint/parser",
plugins: ["prettier"],
rules: {
"prettier/prettier": ["error", { usePrettierrc: true }],
"@typescript-eslint/no-explicit-any": 0,
eqeqeq: ["error", "always"],
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_" },
],
},
};
26 changes: 26 additions & 0 deletions packages/solid/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

*.tgz
3 changes: 3 additions & 0 deletions packages/solid/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage/**
dist/**
pnpm-lock.yaml
14 changes: 14 additions & 0 deletions packages/solid/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"tabWidth": 4,
"useTabs": true,
"semi": true,
"singleQuote": false,
"quoteProps": "as-needed",
"trailingComma": "all",
"bracketSpacing": true,
"bracketSameLine": true,
"arrowParens": "avoid",
"endOfLine": "lf",
"embeddedLanguageFormatting": "auto",
"printWidth": 80
}
21 changes: 21 additions & 0 deletions packages/solid/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
147 changes: 147 additions & 0 deletions packages/solid/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
![Tests](https://github.com/nmathew98/qwery/actions/workflows/main.yml/badge.svg)

## About

Asynchronous state management in Solid made simple.

Most of the use cases of [Solid Query](https://tanstack.com/query/latest/) are covered with a similar API while being 65% lighter.

Solid Query bundle size: [54.6 kB minified](https://bundlephobia.com/package/@tanstack/solid-query)

Solid Qwery bundle size: [19 kB minified](https://bundlephobia.com/package/@b.s/solid-qwery)

Documentation: [Wiki](https://github.com/nmathew98/qwery/wiki/1.-Introduction)

## Features

- CJS + ESM ✅
- Lightweight ✅
- Simple and easy to use ✅
- Retry mechanism ✅
- Caching (with support for async caches) ✅
- Automatic garbage collection ✅
- Remember page scroll ✅
- Distributed transactions (with [txn](https://www.npmjs.com/package/@b.s/txn)) ✅
- Structural sharing ✅
- Subscriptions ✅
- Polling ✅
- Sync updates between tabs with [Broadcast Channel](https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API) ✅
- Determine network status ✅
- Query cancellation ✅
- Suspense ✅
- SSR support ✅

## Usage

### Client-side rendering

```typescript
const { data, dispatch } = useQwery({
initialValue: INITIAL_VALUE,
onChange: onChangeData,
});

// or

const { data, dispatch } = useQwery({
initialValue: () => fetch(API),
onChange: onChangeData,
});

// or

const { data, dispatch } = useQwery({
queryKey: "test-data", // Anything with a `toString` method is supported
onChange: onChangeData,
broadcast: true, // Query key must be set to enable broadcasting updates between tabs
});

// or (Suspense)

const { data, dispatch } = await useQwery({
initialValue: () => fetch(API),
onChange: onChangeData,
suspense: true,
});
```

To opt into caching, provide Qwery context with `provideQweryContext`.

To set cached data ahead of time (prefetching):

```typescript
const qweryContext = useQweryContext();

qweryContext?.setCachedValue(queryKey)(prefetchedData);
```

To invalidate cached data:

```typescript
const qweryContext = useQweryContext();

qweryContext?.makeInvalidateCachedValue(queryKey)(prefetchedData);
```

To use subscriptions:

```typescript
// Assuming its an array of records
const subscribe = async dispatch => {
const generator = createAsyncGenerator();

for await (const nextValue of subscription) {
dispatch(previousValue => {
previousValue.push(nextValue);
});
}
};

const { data, dispatch } = useQwery({
initialValue: () => fetch(API),
onChange: onChangeData,
subscribe: subscribe,
});
```

In a similar vein, for polling:

```typescript
// Assuming its an array of records
const subscribe = dispatch => {
const poll = setInterval(async () => {
const result = await fetch(API);

// Determine the changes and dispatch only the changes
// for references to remain stable if it is an array of records
dispatch(result);
}, 5000);

return () => clearInterval(poll);
};

const { data, dispatch } = useQwery({
initialValue: () => fetch(API),
onChange: onChangeData,
subscribe: subscribe,
});
```

### Server-side rendering

```typescript
const { data, dispatch } = useQwery({
initialValue: INITIAL_VALUE, // Must be provided otherwise `data` is `undefined`
onChange: onChangeData,
});
```

More information in:

- `src/e2e`

## Contributions

- Contributions are welcome, just make a pull request

**_"Man's duality, life and its formalities"_**
69 changes: 69 additions & 0 deletions packages/solid/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"name": "@b.s/solid-qwery",
"version": "1.5.1",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/nmathew98/qwery"
},
"main": "./dist/solid-qwery.umd.cjs",
"module": "./dist/solid-qwery.js",
"types": "./dist/index.d.ts",
"exports": {
"import": "./dist/solid-qwery.js",
"require": "./dist/solid-qwery.umd.cjs",
"types": "./dist/index.d.ts"
},
"description": "Simple composable async state management utilities for SolidJS",
"license": "MIT",
"keywords": [
"crdt",
"solid",
"query",
"asynchronous",
"state",
"management",
"utilities",
"composable",
"database",
"universal",
"distributed",
"transaction",
"saga"
],
"files": [
"dist",
"LICENSE",
"package.json",
"pnpm-lock.yaml",
"README.md",
"tsconfig.json",
"tsconfig.node.json"
],
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"clean": "rm -f *.tgz && rm -rf dist",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"format": "prettier . --write",
"preview": "vite preview",
"test": "vitest run --passWithNoTests",
"test.watch": "vitest --passWithNoTests --watch",
"pack": "pnpm pack"
},
"dependencies": {
"@b.s/incremental": "^2.1.4",
"@b.s/txn": "^1.0.4"
},
"peerDependencies": {
"solid-js": "^1.8.15"
},
"devDependencies": {
"@b.s/qwery-shared": "link:../shared",
"typescript": "^5.2.2",
"vite": "^5.1.4",
"vite-plugin-dts": "^3.7.3",
"vite-plugin-solid": "^2.10.1",
"vitest": "^1.3.1"
}
}
34 changes: 34 additions & 0 deletions packages/solid/src/context/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { createContext, type Component, type ParentProps } from "solid-js";
import { createCacheProvider } from "@b.s/incremental";
import {
ExecutionEnvironment,
useExecutionEnvironment,
} from "../use-execution-environment";
import type { QweryProviderProps } from "./types";
import type { CacheProvider } from "@b.s/incremental";
import { createNoOpCache } from "@b.s/qwery-shared";

export const QweryContext = createContext<CacheProvider>(Object.create(null));

export const QweryProvider: Component<
ParentProps<QweryProviderProps>
> = props => {
const { executionEnvironment } = useExecutionEnvironment();

const createContextValue = () => {
if (
executionEnvironment === ExecutionEnvironment.Server &&
!props.store
) {
return createCacheProvider(createNoOpCache());
}

return createCacheProvider(props.store);
};

return (
<QweryContext.Provider value={createContextValue()}>
{props.children}
</QweryContext.Provider>
);
};
5 changes: 5 additions & 0 deletions packages/solid/src/context/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { CacheStore } from "@b.s/incremental";

export interface QweryProviderProps {
store?: CacheStore;
}
Loading