Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/blue-pans-make.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mobx-tanstack-query": patch
---

remove a lot of useless reactions (replaced it by more simple callbacks)
5 changes: 5 additions & 0 deletions .changeset/every-parks-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mobx-tanstack-query": minor
---

added `lazy` option for queries and mutations which work on lazy observables from mobx
2 changes: 2 additions & 0 deletions docs/api/InfiniteQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Class wrapper for [@tanstack-query/core infinite queries](https://tanstack.com/q

[_See docs for Query_](/api/Query)

**All documentation about properties and methods of infinite query can be found in the original documentation [here](https://tanstack.com/query/latest/docs/framework/react/reference/useInfiniteQuery)**

[Reference to source code](/src/infinite-query.ts)

## Usage
Expand Down
64 changes: 43 additions & 21 deletions docs/api/Mutation.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Mutation
# Mutation

Class wrapper for [@tanstack-query/core mutations](https://tanstack.com/query/latest/docs/framework/react/guides/mutations) with **MobX** reactivity
Class wrapper for [@tanstack-query/core mutations](https://tanstack.com/query/latest/docs/framework/react/guides/mutations) with **MobX** reactivity

[Reference to source code](/src/mutation.ts)
**All documentation about properties and methods of mutation can be found in the original documentation [here](https://tanstack.com/query/latest/docs/framework/react/reference/useMutation)**

## Usage
[Reference to source code](/src/mutation.ts)

## Usage

Create an instance of `Mutation` with [`mutationFn`](https://tanstack.com/query/latest/docs/framework/react/guides/mutations) parameter

Expand Down Expand Up @@ -36,12 +38,13 @@ const petCreateMutation = new Mutation({
const result = await petCreateMutation.mutate('Fluffy');
console.info(result.data, result.isPending, result.isError);

```
```

## Built-in Features

## Built-in Features
### `abortSignal` option

### `abortSignal` option
This field is necessary to kill all reactions and subscriptions that are created during the creation of an instance of the `Mutation` class
This field is necessary to kill all reactions and subscriptions that are created during the creation of an instance of the `Mutation` class

```ts
const abortController = new AbortController();
Expand All @@ -61,27 +64,46 @@ abortController.abort();

This is alternative for `destroy` method

### `destroy()` method
This method is necessary to kill all reactions and subscriptions that are created during the creation of an instance of the `Mutation` class
### `lazy` option

This option enables "lazy" mode of the mutation. That means that all subscriptions and reaction will be created only when you request result for this mutation.

Example:

```ts
const mutation = createMutation(queryClient, () => ({
lazy: true,
mutationFn: async () => {
// api call
},
}));

// happens nothing
// no reactions and subscriptions will be created
```

### `destroy()` method

This method is necessary to kill all reactions and subscriptions that are created during the creation of an instance of the `Mutation` class

This is alternative for `abortSignal` option
This is alternative for `abortSignal` option

### method `mutate(variables, options?)`
Runs the mutation. (Works the as `mutate` function in [`useMutation` hook](https://tanstack.com/query/latest/docs/framework/react/reference/useMutation))
### method `mutate(variables, options?)`

### hook `onDone()`
Subscribe when mutation has been successfully finished
Runs the mutation. (Works the as `mutate` function in [`useMutation` hook](https://tanstack.com/query/latest/docs/framework/react/reference/useMutation))

### hook `onError()`
Subscribe when mutation has been finished with failure
### hook `onDone()`

### method `reset()`
Reset current mutation
Subscribe when mutation has been successfully finished

### property `result` <Badge type="info" text="observable.deep" />
Mutation result (The same as returns the [`useMutation` hook](https://tanstack.com/query/latest/docs/framework/react/reference/useMutation))
### hook `onError()`

Subscribe when mutation has been finished with failure

### method `reset()`

Reset current mutation

### property `result` <Badge type="info" text="observable.deep" />

Mutation result (The same as returns the [`useMutation` hook](https://tanstack.com/query/latest/docs/framework/react/reference/useMutation))
Loading