-
-
Notifications
You must be signed in to change notification settings - Fork 36
Open
Labels
Milestone
Description
In this repository, the discussions section is disabled. I believe my question should be located there.
I would like to see some API like this but maybe farfetched has a different approach to solving the same case.
import { createJsonQuery } from '@farfetched/core'
import { runtypeContract } from '@farfetched/runtypes';
import { Record, Literal } from 'runtypes';
const NotFoundUserResponse = Record({
result: Literal(false),
error: Record({
type: Literal('USER_NOT_FOUND'),
})
});
const SuccessUserResponse = Record({
data: User,
result: Literal(true)
});
const query = createJsonQuery({
// other options...
contracts: {
notFound: runtypeContract(NotFoundUserResponse),
success: runtypeContract(SuccessUserResponse),
}
});
sample({
clock: query.finished.notFound,
target: navigateUserToHomePageFx,
});
sample({
clock: query.finished.success,
// do something when everthing is ok
});
sample({
clock: query.finished.unexpected,
// do something when server response type is unexpected
});Shiyan7 and spotsccc