americanexpress / fetchye

✨ If you know how to use Fetch, you know how to use Fetchye [fetch-yae]. Simple React Hooks, Centralized Cache, Infinitely Extensible.
Apache License 2.0
43 stars 22 forks source link

feat(oneFetchye): make even cleaner api for fetchtye #90

Closed code-forger closed 10 months ago

code-forger commented 10 months ago

Description

Create a new, cleaner, way of imperatively calling fetchye in One App

Motivation and Context

requiring callers to use makeOneServerFetchye is both messy, and incredibly confusing, since this function works in the client too.

Since redux's dispatch must always be in scope for makeOneServerFetchye to be called, this function can be transformed to a thunk generator.

That takes this code:

  loadModuleData: async ({ store: { dispatch, getState }, fetchClient }) => {
    const fetchye = makeOneServerFetchye({
      store: { dispatch, getState },
      fetchClient,
    });

    await fetchye('http://example.com/api/books/');
  },

To this code:

  loadModuleData: async ({ store: { dispatch  }) => dispatch(oneFetchye('http://example.com/api/books/')),

in all relevant contexts.

NOTE: This does not change the api at all, all params that the imperative fetchye made by makeOneServerFetchye took, the thunk generator still takes. You can still await the dispatch, to get back into your hand the exact returned value as before.

This is purely syntactic sugar.

How Has This Been Tested?

Unit tests, run in a tenancy

Types of Changes

Checklist:

What is the Impact to Developers Using Fetchye?

Simpler API

codesandbox-ci[bot] commented 10 months ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 3fc48eabc118b4556cd88acbc48cf1f34c6a3837:

Sandbox Source
quick-install Configuration
fetchye-provider-install Configuration
fetchye-redux-provider-install Configuration
nextjs-fetchye-ssr Configuration