You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit was created on GitHub.com and signed with GitHub’s verified signature.
The key has expired.
feat: support multiple endpoints with the same name (#27)
Previously the name provieded to `api.get('/the-name')` had to be unique.
Internally we used that name for a few internal maps that assumed they
would always be unique.
However, we want to support the ability for `createApi` to support
scenariors where you have the same name HTTP endpoint defined multiple
times. Why would someone want that? Because we have special sagas that
can be used to provide additional functionality to our endpoints -- like
polling -- we want to ensure they can use them without colliding with
more basic endpoints.
```ts
const api = createApi();
const action = api.get('/');
const pollAction = api.get('/', { saga: poll(5 * 1000) });
dispatch(pollAction());
dispatch(action());
```
Here we have a case where we want to duplicate
the name because it relates to the API endpoint we want to hit.
To fix this we now support the ability to provide an array for the name
of the endpoint.
```ts
const api = createApi();
const action = api.get('/');
const pollAction = api.get(['/', 'poller'], { saga: poll(5 * 1000) });
dispatch(pollAction());
dispatch(action());
```
The first part is the string used to generate the url with our
`urlParser` middleware. The remaining parts are used for making the
name unique and are otherwise not used.
Although other middleware could be creative with using the array of
strings.