Skip to content

Commit

Permalink
Merge branch 'main' into docs/vue-reactivity-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni authored Dec 24, 2024
2 parents 84b6f03 + 4f90639 commit 23f0901
Show file tree
Hide file tree
Showing 145 changed files with 3,735 additions and 2,654 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
TAG: ${{ inputs.tag }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4.5.0
uses: codecov/codecov-action@v4.6.0
with:
directory: packages
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
if: ${{ always() }}
run: npx nx-cloud stop-all-agents
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4.5.0
uses: codecov/codecov-action@v4.6.0
with:
directory: packages
env:
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22.4.0
22.12.0
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ If you have been assigned to fix an issue or develop a new feature, please follo
pnpm install
```

- We use [pnpm](https://pnpm.io/) v8 for package management (run in case of pnpm-related issues).
- We use [pnpm](https://pnpm.io/) v9 for package management (run in case of pnpm-related issues).

```bash
corepack enable && corepack prepare
Expand Down
4 changes: 4 additions & 0 deletions docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,10 @@
"label": "Basic",
"to": "framework/angular/examples/basic"
},
{
"label": "Auto Refetching / Polling / Realtime",
"to": "framework/angular/examples/auto-refetching"
},
{
"label": "Pagination",
"to": "framework/angular/examples/pagination"
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/react/guides/query-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ queryClient.setQueryData(groupOptions(42).queryKey, newGroups)

[//]: # 'Example1'

For Infinite Queries, a separate `infiniteQueryOptions` helper is available.
For Infinite Queries, a separate [`infiniteQueryOptions`](../reference/infiniteQueryOptions.md) helper is available.
4 changes: 2 additions & 2 deletions docs/framework/react/plugins/broadcastQueryClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ broadcastQueryClient({ queryClient, broadcastChannel })
An object of options:

```tsx
interface broadcastQueryClient {
interface BroadcastQueryClientOptions {
/** The QueryClient to sync */
queryClient: QueryClient
/** This is the unique channel name that will be used
Expand All @@ -56,6 +56,6 @@ The default options are:

```tsx
{
broadcastChannel = 'react-query',
broadcastChannel = 'tanstack-query',
}
```
2 changes: 1 addition & 1 deletion docs/framework/react/react-native.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Enabled can also be set to a callback to support disabling queries on out of foc
import React from 'react'
import { useFocusEffect } from '@react-navigation/native'

export function useQueryFocusAware(notifyOnChangeProps?: NotifyOnChangeProps) {
export function useQueryFocusAware() {
const focusedRef = React.useRef(true)

useFocusEffect(
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/react/reference/infiniteQueryOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ infiniteQueryOptions({

**Options**

You can generally pass everything to `queryOptions` that you can also pass to [`useInfiniteQuery`](../useInfiniteQuery). Some options will have no effect when then forwarded to a function like `queryClient.prefetchInfiniteQuery`, but TypeScript will still be fine with those excess properties.
You can generally pass everything to `infiniteQueryOptions` that you can also pass to [`useInfiniteQuery`](../useInfiniteQuery). Some options will have no effect when then forwarded to a function like `queryClient.prefetchInfiniteQuery`, but TypeScript will still be fine with those excess properties.

- `queryKey: QueryKey`
- **Required**
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/react/reference/useMutation.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mutate(variables, {
- `mutationKey: unknown[]`
- Optional
- A mutation key can be set to inherit defaults set with `queryClient.setMutationDefaults`.
- `networkMode: 'online' | 'always' | 'offlineFirst`
- `networkMode: 'online' | 'always' | 'offlineFirst'`
- Optional
- defaults to `'online'`
- see [Network Mode](../../guides/network-mode) for more information.
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/react/reference/useQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const {
- `staleTime: number | ((query: Query) => number)`
- Optional
- Defaults to `0`
- The time in milliseconds after data is considered stale. This value only applies to the hook it is defined on.
- The time in milliseconds after which data is considered stale. This value only applies to the hook it is defined on.
- If set to `Infinity`, the data will never be considered stale
- If set to a function, the function will be executed with the query to compute a `staleTime`.
- `gcTime: number | Infinity`
Expand Down
5 changes: 4 additions & 1 deletion docs/framework/vue/guides/query-keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ ref: docs/framework/react/guides/query-keys.md
```js
function useTodos(todoId) {
const queryKey = ['todos', todoId]
return useQuery(queryKey, () => fetchTodoById(todoId.value))
return useQuery({
queryKey,
queryFn: () => fetchTodoById(todoId.value),
})
}
```

Expand Down
2 changes: 0 additions & 2 deletions docs/reference/QueryClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ Its available methods are:

If the query exists and the data is not invalidated or older than the given `staleTime`, then the data from the cache will be returned. Otherwise it will try to fetch the latest data.

> The difference between using `fetchQuery` and `setQueryData` is that `fetchQuery` is async and will ensure that duplicate requests for this query are not created with `useQuery` instances for the same query are rendered while the data is fetching.
```tsx
try {
const data = await queryClient.fetchQuery({ queryKey, queryFn })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Node.js",
"image": "mcr.microsoft.com/devcontainers/javascript-node:22"
}
6 changes: 6 additions & 0 deletions examples/angular/auto-refetching/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @ts-check

/** @type {import('eslint').Linter.Config} */
const config = {}

module.exports = config
6 changes: 6 additions & 0 deletions examples/angular/auto-refetching/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# TanStack Query Angular auto-refetching example

To run this example:

- `npm install` or `yarn` or `pnpm i` or `bun i`
- `npm run start` or `yarn start` or `pnpm start` or `bun start`
104 changes: 104 additions & 0 deletions examples/angular/auto-refetching/angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"cli": {
"packageManager": "pnpm",
"analytics": false,
"cache": {
"enabled": false
}
},
"newProjectRoot": "projects",
"projects": {
"auto-refetching": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"inlineTemplate": true,
"inlineStyle": true,
"skipTests": true
},
"@schematics/angular:class": {
"skipTests": true
},
"@schematics/angular:directive": {
"skipTests": true
},
"@schematics/angular:guard": {
"skipTests": true
},
"@schematics/angular:interceptor": {
"skipTests": true
},
"@schematics/angular:pipe": {
"skipTests": true
},
"@schematics/angular:resolver": {
"skipTests": true
},
"@schematics/angular:service": {
"skipTests": true
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular/build:application",
"options": {
"outputPath": "dist/auto-refetching",
"index": "src/index.html",
"browser": "src/main.ts",
"polyfills": ["zone.js"],
"tsConfig": "tsconfig.app.json",
"assets": ["src/favicon.ico", "src/assets"],
"styles": [],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular/build:dev-server",
"configurations": {
"production": {
"buildTarget": "auto-refetching:build:production"
},
"development": {
"buildTarget": "auto-refetching:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular/build:extract-i18n",
"options": {
"buildTarget": "auto-refetching:build"
}
}
}
}
}
}
28 changes: 28 additions & 0 deletions examples/angular/auto-refetching/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@tanstack/query-example-angular-auto-refetching",
"type": "module",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development"
},
"private": true,
"dependencies": {
"@angular/common": "^19.1.0-next.0",
"@angular/compiler": "^19.1.0-next.0",
"@angular/core": "^19.1.0-next.0",
"@angular/platform-browser": "^19.1.0-next.0",
"@angular/platform-browser-dynamic": "^19.1.0-next.0",
"@tanstack/angular-query-experimental": "^5.62.9",
"rxjs": "^7.8.1",
"tslib": "^2.6.3",
"zone.js": "^0.15.0"
},
"devDependencies": {
"@angular/build": "^19.0.2",
"@angular/cli": "^19.0.2",
"@angular/compiler-cli": "^19.1.0-next.0",
"typescript": "5.7.2"
}
}
11 changes: 11 additions & 0 deletions examples/angular/auto-refetching/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ChangeDetectionStrategy, Component } from '@angular/core'
import { AutoRefetchingExampleComponent } from './components/auto-refetching.component'

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'app-root',
standalone: true,
template: `<auto-refetching-example />`,
imports: [AutoRefetchingExampleComponent],
})
export class AppComponent {}
28 changes: 28 additions & 0 deletions examples/angular/auto-refetching/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
provideHttpClient,
withFetch,
withInterceptors,
} from '@angular/common/http'
import {
QueryClient,
provideTanStackQuery,
withDevtools,
} from '@tanstack/angular-query-experimental'
import { mockInterceptor } from './interceptor/mock-api.interceptor'
import type { ApplicationConfig } from '@angular/core'

export const appConfig: ApplicationConfig = {
providers: [
provideHttpClient(withFetch(), withInterceptors([mockInterceptor])),
provideTanStackQuery(
new QueryClient({
defaultOptions: {
queries: {
gcTime: 1000 * 60 * 60 * 24, // 24 hours
},
},
}),
withDevtools(),
),
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<div>
<h1>Auto Refetch with stale-time set to {{ intervalMs() }}ms</h1>
<p>
This example is best experienced on your own machine, where you can open
multiple tabs to the same localhost server and see your changes propagate
between the two.
</p>
<label>
Query Interval speed (ms):
<input [value]="intervalMs()" (input)="inputChange($event)" />
<span
[ngStyle]="{
display: 'inline-block',
marginLeft: '.5rem',
width: '10px',
height: '10px',
background: tasks.isFetching() ? 'green' : 'transparent',
transition: !tasks.isFetching() ? 'all .3s ease' : 'none',
borderRadius: '100%',
transform: 'scale(2)',
}"
></span>
</label>
<h2>Todo List</h2>

<input placeholder="Enter something" (keydown.enter)="addItem($event)" />
<ul>
@for (item of tasks.data(); track item) {
<li>{{ item }}</li>
}
</ul>
<div>
<button (click)="clearTasks()">Clear All</button>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {
ChangeDetectionStrategy,
Component,
inject,
signal,
} from '@angular/core'
import {
injectMutation,
injectQuery,
} from '@tanstack/angular-query-experimental'
import { NgStyle } from '@angular/common'
import { TasksService } from '../services/tasks.service'

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'auto-refetching-example',
standalone: true,
templateUrl: './auto-refetching.component.html',
imports: [NgStyle],
})
export class AutoRefetchingExampleComponent {
#tasksService = inject(TasksService)

intervalMs = signal(1000)

tasks = injectQuery(() => this.#tasksService.allTasks(this.intervalMs()))

addMutation = injectMutation(() => this.#tasksService.addTask())
clearMutation = injectMutation(() => this.#tasksService.clearAllTasks())

clearTasks() {
this.clearMutation.mutate()
}

inputChange($event: Event) {
const target = $event.target as HTMLInputElement
this.intervalMs.set(Number(target.value))
}

addItem($event: Event) {
const target = $event.target as HTMLInputElement
const value = target.value
this.addMutation.mutate(value)
target.value = ''
}
}
Loading

0 comments on commit 23f0901

Please sign in to comment.