equt / fetch Goto Github PK
View Code? Open in Web Editor NEWDeclarative WHATWG Fetch Wrapper
License: MIT License
Declarative WHATWG Fetch Wrapper
License: MIT License
Currently, the when
could only accept a lazy boolean value, indicating whether the giving combinator should be running or not. We should instead extend the prediction function, to allow it to inspect the data flow.
pipe(
request,
asJSON(),
decodeAs(/* */),
when(
({ succeeded }) => succeeded,
fail(() => /* */)
),
)
From the user's perspective, there should be three components
Retry Policy
type Policy = Nullable<number>
If it's non-nullable, i.e., not undefined
or null
, the executor will wait that amount of time, then re-execute it.
Retry Strategy
type Strategy<E> = {
(error: E, times: number): Policy
}
Strategy will be called if there is an error, and it decides when & how the retry should happen.
HoC Retry
retry
be placed?retry
handle the bailed?withUsername
, withPassword
, and decodeAs
combinatorsbuild
alternative to runFetchM
variants, which will return the built Either<E, Request>
without sending itDOM.Iterable
withSignal
and/or withTimeout
occur multiple times (requires TypeScript 5.5)Currently, errors could come from two different sources
throws
. According to the spec, it should either be a DOMException
named AbortError
, or TypeError
for the rest.Response
has a property called type
, which could be error
. This is set, for example, if the redirect
in Request
is error
.We would like to have something like
const getUserProfile = pipe(
base,
withJSON((id: number, size: '1x' | '2x' = '2x') => ({ id, size })),
asJSON(),
runFetchMFlippedPT,
)
, where the sig could be automatically inferred by the compiler, which in this case, is (endpoint: string, args: { id: number; size?: '1x' | '2x' }) => Promise<Json>
.
I'm gonna suspend this until fetch
gets implemented in Node, which should happen after Node 18 lands.
Fetcher
type is defined asexport type Fetcher<
Data = unknown,
SWRKey extends Key = Key
> = SWRKey extends () => readonly [...infer Args] | null | undefined | false
? (...args: [...Args]) => FetcherResponse<Data>
: SWRKey extends readonly [...infer Args]
? (...args: [...Args]) => FetcherResponse<Data>
: SWRKey extends () => infer Arg | null | undefined | false
? (...args: [Arg]) => FetcherResponse<Data>
: SWRKey extends null | undefined | false
? never
: SWRKey extends infer Arg
? (...args: [Arg]) => FetcherResponse<Data>
: never
As for code using @equt/fetch
, dependencies are
+ export const createUser = (username: string, password: string) =>
pipe(
base,
withMethod('POST'),
withJSON({
username,
password,
}),
+ runFetchM('user'),
)
We don't actually use string interpolation to add params to create the desired URL, so our choices are either pass them into an Array
, or as a Record
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.