Skip to content

Commit ec93bbb

Browse files
committed
Merge remote-tracking branch 'origin/master' into refactor/remove-deprecatations
2 parents 9d6de94 + a454dbf commit ec93bbb

17 files changed

Lines changed: 2782 additions & 1707 deletions

.changeset/jolly-parrots-cover.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"mobx-tanstack-query": patch
3+
---
4+
5+
[internal] update deps (dev) to latest

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# mobx-tanstack-query
22

3+
## 6.16.0
4+
5+
### Minor Changes
6+
7+
- [`da6909d`](https://github.com/js2me/mobx-tanstack-query/commit/da6909daed63441f63e8240eea32c31b37c7f668) Thanks [@js2me](https://github.com/js2me)! - added `lazyDelay` option for queries and mutations as features
8+
9+
## 6.15.1
10+
11+
### Patch Changes
12+
13+
- [`eeb0abf`](https://github.com/js2me/mobx-tanstack-query/commit/eeb0abf73cbbe75551d94eb164cc25b0b12a75a5) Thanks [@js2me](https://github.com/js2me)! - fixed `resultObservable` work with merging with query client
14+
15+
## 6.15.0
16+
17+
### Minor Changes
18+
19+
- [`73207cc`](https://github.com/js2me/mobx-tanstack-query/commit/73207cc8e22303d0a2975bac12eedcd4c14945a0) Thanks [@js2me](https://github.com/js2me)! - added `resultObservable` query and mutation features
20+
321
## 6.14.1
422

523
### Patch Changes

docs/api/Mutation.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,48 @@ const mutation = createMutation(queryClient, () => ({
152152
// no reactions and subscriptions will be created
153153
```
154154

155+
### `lazyDelay` option <Badge type="tip">MutationFeature</Badge>
156+
157+
[_Can be specified using `QueryClient`_](https://js2me.github.io/mobx-tanstack-query/api/QueryClient.html#mutationfeatures)
158+
159+
Only applies when [`lazy`](#lazy-option) is enabled.
160+
161+
After the last MobX observer stops reading the mutation **`result`**, the library keeps the `MutationObserver` subscription alive for an extra **`lazyDelay` milliseconds** before tearing it down. This uses the `endDelay` option of [`lazyObserve`](https://www.npmjs.com/package/yummies) from `yummies/mobx`, same as for [`Query` `lazyDelay`](https://js2me.github.io/mobx-tanstack-query/api/Query.html#lazydelay-option-queryfeature).
162+
163+
Use it to smooth over short-lived UI changes so you do not drop the observer subscription on every transient unmount.
164+
165+
When **`lazyDelay`** is omitted, teardown follows the same rules as for [`Query` `lazyDelay`](https://js2me.github.io/mobx-tanstack-query/api/Query.html#lazydelay-option-queryfeature) (no extra delay unless you set a number).
166+
167+
```ts
168+
const mutation = new Mutation({
169+
queryClient,
170+
lazy: true,
171+
lazyDelay: 300,
172+
mutationFn: async () => api.updatePet(),
173+
});
174+
```
175+
176+
### `resultObservable` <Badge type="tip">MutationFeature</Badge>
177+
178+
[_Can be specified using `QueryClient`_](https://js2me.github.io/mobx-tanstack-query/api/QueryClient.html#mutationfeatures)
179+
180+
Chooses how MobX observes the mutation **`result`** property (the `MutationObserverResult`). The library applies `annotation.observable()` from [`yummies/mobx`](https://github.com/js2me/yummies). [`Query`](https://js2me.github.io/mobx-tanstack-query/api/Query.html#resultobservable-queryfeature) stores the payload on a private `_result` and exposes TanStack fields via getters; **`Mutation` decorates the public `result` field directly** — there is no `_result`.
181+
182+
- **Default** — when omitted, behaviour matches **`'deep'`** (deep observability for plain objects and arrays in the result).
183+
- **`'ref'`** — only the reference to the result object is tracked; reactions run when the whole result is replaced, not when nested fields change in place.
184+
- **`'shallow'`** / **`'struct'`** — shallow or structural comparison for nested properties.
185+
- **`false`** — do not decorate `result` (rare; you lose automatic MobX tracking for the result blob).
186+
187+
Example:
188+
189+
```ts
190+
const mutation = new Mutation({
191+
queryClient,
192+
resultObservable: 'ref',
193+
mutationFn: async (name: string) => api.createPet(name),
194+
});
195+
```
196+
155197
### `destroy()` method
156198

157199
This method is necessary to kill all reactions and subscriptions that are created during the creation of an instance of the `Mutation` class
@@ -177,3 +219,7 @@ Reset current mutation
177219
### property `result` <Badge type="info" text="observable.deep" />
178220

179221
Mutation result (The same as returns the [`useMutation` hook](https://tanstack.com/query/latest/docs/framework/react/reference/useMutation))
222+
223+
::: info `observable.deep` is configurable
224+
The badge reflects the **default**: the public `result` property is decorated as deep observable (unlike `Query`, which uses a private `_result` behind getters). Change the MobX flavour with [`resultObservable`](#resultobservable-mutationfeature) (`ref`, `shallow`, `struct`, `true`, or `false`).
225+
:::

docs/api/Query.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ This field is needed for `enableOnDemand` option
295295

296296
Query original result (The same as returns the [`useQuery` hook](https://tanstack.com/query/latest/docs/framework/react/reference/useQuery))
297297

298+
::: info `observable.deep` is configurable
299+
The badge reflects the **default**: the internal `_result` field is decorated as deep observable. You can change the MobX flavour (`ref`, `shallow`, `struct`, `true`, or `false`) with the [`resultObservable`](#resultobservable-queryfeature) query feature.
300+
:::
301+
298302
### `setData(updater, options)`
299303

300304
Set data for current query (Uses [queryClient.setQueryData](https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientsetquerydata))
@@ -641,6 +645,32 @@ const query = createQuery(queryClient, () => ({
641645
// no reactions and subscriptions will be created
642646
```
643647

648+
### `lazyDelay` option <Badge type="tip">QueryFeature</Badge>
649+
650+
[_Can be specified using `QueryClient`_](https://js2me.github.io/mobx-tanstack-query/api/QueryClient.html#queryfeatures)
651+
652+
Only applies when [`lazy`](#lazy-option-queryfeature) is enabled.
653+
654+
After the last MobX observer stops reading the query result, the library keeps the TanStack `QueryObserver` subscription alive for an extra **`lazyDelay` milliseconds** before tearing it down. Internally this maps to the `endDelay` option of [`lazyObserve`](https://www.npmjs.com/package/yummies) from `yummies/mobx`.
655+
656+
Use this to avoid churn when UI code briefly mounts and unmounts (for example route transitions or conditional panels): if something starts observing the result again before the delay elapses, the existing subscription is reused and you avoid an immediate unsubscribe/resubscribe cycle.
657+
658+
- **Omitted or `undefined`** — teardown runs as soon as nothing observes the result (equivalent to `endDelay: false` in [`lazyObserve`](https://www.npmjs.com/package/yummies) / `yummies/mobx`).
659+
- **A positive number** — milliseconds to wait after the last observer detaches before unsubscribing from the TanStack observer.
660+
661+
Example (global default via `QueryClient`):
662+
663+
```ts
664+
const queryClient = new QueryClient({
665+
defaultOptions: {
666+
queries: {
667+
lazy: true,
668+
lazyDelay: 300,
669+
},
670+
},
671+
});
672+
```
673+
644674
### `transformError` <Badge type="tip">QueryFeature</Badge>
645675

646676
[_Can be specified using `QueryClient`_](https://js2me.github.io/mobx-tanstack-query/api/QueryClient.html#queryfeatures)
@@ -749,6 +779,28 @@ const query = new Query({
749779
})
750780
```
751781

782+
### `resultObservable` <Badge type="tip">QueryFeature</Badge>
783+
784+
[_Can be specified using `QueryClient`_](https://js2me.github.io/mobx-tanstack-query/api/QueryClient.html#queryfeatures)
785+
786+
Chooses how MobX observes the internal TanStack Query result object (`_result`). The library applies [`annotation.observable()`](https://github.com/js2me/yummies) from `yummies/mobx`, so this maps directly to MobX flavours: `ref`, `deep`, `shallow`, `struct`, or `true` / `false`.
787+
788+
- **Default** — when omitted, behaviour matches **`'deep'`** (deep observability for plain objects and arrays in the result).
789+
- **`'ref'`** — only the reference to the result object is tracked; use when the observer should react when the whole result is replaced, not when nested fields change in place.
790+
- **`'shallow'`** / **`'struct'`** — shallow or structural comparison for nested properties.
791+
- **`false`** — do not decorate `_result` with an observable annotation (rare; you lose automatic MobX tracking for the result blob).
792+
793+
Example:
794+
795+
```ts
796+
const query = new Query({
797+
queryClient,
798+
resultObservable: 'ref',
799+
queryKey: ['pets'],
800+
queryFn: async () => api.fetchPets(),
801+
});
802+
```
803+
752804
## Recommendations
753805

754806
### Don't forget about `abortSignal`s or `lazy` option

docs/api/QueryClient.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const queryClient = new QueryClient({
4444
defaultOptions: {
4545
queries: {
4646
lazy: true,
47+
// lazyDelay: 300,
4748
enableOnDemand: true,
4849
// resetOnDestroy: false,
4950
// dynamicOptionsUpdateDelay: undefined,
@@ -71,6 +72,7 @@ export const queryClient = new QueryClient({
7172
// invalidateByKey: true,
7273
// resetOnDestroy: true,
7374
lazy: true,
75+
// lazyDelay: 300,
7476
// transformError: (error) => error,
7577
},
7678
},

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mobx-tanstack-query",
3-
"version": "6.14.1",
3+
"version": "6.16.0",
44
"scripts": {
55
"prepare": "pnpm dev:install-hooks",
66
"clean": "rimraf dist",
@@ -50,31 +50,31 @@
5050
},
5151
"dependencies": {
5252
"linked-abort-controller": "^1.1.1",
53-
"yummies": "^7.12.0"
53+
"yummies": "^7.19.4"
5454
},
5555
"devDependencies": {
56-
"@biomejs/biome": "^2.4.10",
56+
"@biomejs/biome": "^2.4.13",
5757
"@changesets/changelog-github": "^0.6.0",
58-
"@changesets/cli": "^2.30.0",
58+
"@changesets/cli": "^2.31.0",
5959
"@testing-library/react": "^16.3.2",
6060
"@types/lodash-es": "^4.17.12",
61-
"@types/node": "^20.19.37",
61+
"@types/node": "^20.19.39",
6262
"@types/react": "^18.3.28",
6363
"@vitejs/plugin-react-swc": "^4.3.0",
64-
"@vitest/coverage-istanbul": "^4.1.2",
64+
"@vitest/coverage-istanbul": "^4.1.5",
6565
"commitfmt": "^1.0.4",
6666
"js2me-biome-config": "^1.1.0",
67-
"jsdom": "^29.0.1",
67+
"jsdom": "^29.1.0",
6868
"lefthook": "^1.13.6",
6969
"nodemon": "^3.1.14",
7070
"rimraf": "^6.1.3",
71-
"sborshik": "^3.0.0",
72-
"terser": "^5.46.1",
71+
"sborshik": "^3.5.0",
72+
"terser": "^5.46.2",
7373
"tsx": "^4.21.0",
74-
"typescript": "^6.0.2",
75-
"vite": "^8.0.3",
74+
"typescript": "^6.0.3",
75+
"vite": "^8.0.10",
7676
"vite-plugin-dts": "^4.5.4",
77-
"vitest": "^4.1.2"
77+
"vitest": "^4.1.5"
7878
},
7979
"packageManager": "pnpm@9.5.0+sha512.140036830124618d624a2187b50d04289d5a087f326c9edfc0ccd733d76c4f52c3a313d4fc148794a2a9d81553016004e6742e8cf850670268a7387fc220c903"
8080
}

0 commit comments

Comments
 (0)