v0.5 Chew Lan
Photo by Maria Goroshko
Why Chew Lan?
Chew Lan is a large artificial lake in the Khao Sok National Park and one of the most calm places in the world. Plenty of APIs in Farfetched were invented there.
update
operator is there! It allows you to update Query on top of Mutation result 👇
import { update } from '@farfetched/core';
update(postQuery, {
on: editPostTitleMutation,
by: {
success(state) {
const oldPost = state.query.result;
const editions = state.mutation.params;
return {
result: { ...oldPost, title: editions.title },
refetch: true,
};
},
},
});
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.5.1
0.5.0
@farfetched/react
Minor Changes
- e0802dd: Deprecate
@farfetched/react
in favour of@@unitShape
protocol
@farfetched/core
Minor Changes
- 57abab2: Add config
concurrency.strategy
forcreateJsonQuery
factory - dcbdcaa: Support more formats in Time
- e914ba2: Add operator
update
to connect Query and Mutation - 127f78a: Pass params of source Queries to
fn
inconnectQuery
- e0802dd: Support
@@unitShape
protocol of Effector
Patch Changes