v0.6 Huai Nam Dang
Photo by Maria Goroshko
Why Huai Nam Dang?
Huai Nam Dang is a national park in the North of Thailand. It is one of the coldest places in Thailand (like 12 °C or 53 °F) 🥶
It's pretty compact release with only one notable change - attachOperation
which allows coping of Query or Mutation with altering parameters.
import { createStore } from 'effector';
import { attachOperation, createQuery } from '@farfetched/core';
const $externalStore = createStore(12);
const originalQuery = createQuery({
handler: async (params: string) => 'some data',
});
const attachedQuery = attachOperation(originalQuery, {
source: $externalStore,
mapParams: (params: number, externalSource) => (params + externalSource).toString(),
});
It also includes a couple of minor improvements and bug fixes. Read the full changelog below.
Migration guide
Since v0.5, Farfetched supports @@unitShape
protocol, so you can use useUnit
from effector-react
and effector-solid
to subscribe to custom entities like Query and Mutation.
Do not use @farfetched/react
Package @farfetched/react
is deprecated, just use useUnit
from effector-react
instead of useQuery
and useMutation
🪄
import { useQuery, useMutation } from '@farfetched/react';
import { useUnit } from 'effector-react';
function User() {
const { data: user } = useQuery(userQuery);
const { data: user } = useUnit(userQuery);
const { start: deleteAccount } = useMutation(deleteAccountMutation);
const { start: deleteAccount } = useUnit(deleteAccountMutation);
return (
<div>
<p>Name: {user.name}</p>
<button onClick={deleteAccount}>Delete my account</button>
</div>
);
}
Do not use useMutation
from @farfetched/solid
Function useMutation
from @farfetched/solid
is deprecated, just use useUnit
from effector-solid
instead 🪄
import {
createQueryResource,
useMutation,
} from '@farfetched/solid';
import { useUnit } from 'effector-react';
function User() {
const [user] = createQueryResource(userQuery);
const { start: deleteAccount } = useMutation(deleteAccountMutation);
const { start: deleteAccount } = useUnit(deleteAccountMutation);
return (
<Suspense fallback={<p>Loading...</p>}>
<div>
<p>Name: {user().name}</p>
<button onClick={deleteAccount}>Delete my account</button>
</div>
</Suspense>
);
}
TIP
Q: Why createQueryResource
is still there?
A: Because @@unitShape
protocol supports only shapes of units, not custom operations like binding Query with Suspense of Solid.
Full changelog
0.6.4
@farfetched/core
Patch Changes
- 5da04bf: Fix type inference in
createQuery
ineffect
andmapData
overload
0.6.3
0.6.2
0.6.1
0.6.0
@farfetched/core
Minor Changes
- 521834d: Allow passing abort signal to
createJsonQuery
andcreateJsonMutation
- f7def6f: Ignore
params
whilecache
createJsonQuery
to decrease number of cache misses - b57c5ee: Add
attachOperation
operator - c2431af: Parse response in
httpError
increateJson*
as JSON - b57c5ee: Expose
initialData
in Query meta
Patch Changes
- fa4a40f: Return
null
for empty response increateJsonApiRequest
instead ofpreparationError
@farfetched/solid
Minor Changes
- dc6ee4c: Delete deprecated
useMutation
in favour of @@unitShape protocol