GithubHelp home page GithubHelp logo

fetch's Introduction

Declarative WHATWG Fetch Wrapper

codecov npm

fetch's People

Contributors

equt avatar

Forkers

lgtm-migrator

fetch's Issues

Allow `when` Combinator to Inspect Last Output

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(() => /* */)
  ),
)

Higher Order Combinator: Retry

Proposal

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

TODO

  • Where should the retry be placed?
  • Should retry handle the bailed?

Tracking Issue for 5.0

TODO

  • Remove withUsername, withPassword, and decodeAs combinators
  • Provide a build alternative to runFetchM variants, which will return the built Either<E, Request> without sending it
  • Correct code doc links
  • Require DOM.Iterable
  • Allow withSignal and/or withTimeout occur multiple times (requires TypeScript 5.5)

References

Make `Lazy` into Function

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>.

Integrate with SWR Libs

Research

Vercel's SWR Lib

export 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.

  • The Global Error Report section really convinces me a lot.
    • But if the error gets resolved inside the component, will it still be reported to the global wrapper?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.