Skip to content

Releases: redux-saga/saga-query

`createPipe` better types

10 Feb 16:42
526f865
Compare
Choose a tag to compare
v6.2.3

chore(createPipe): better type inference

`createApi` better types

10 Feb 16:20
121da98
Compare
Choose a tag to compare

For when you provide a ctx in a function endpoint definition without props

createApi better types fix

10 Feb 16:03
7f99eec
Compare
Choose a tag to compare

Trying to allow end-user to override ctx in function definition of their endpoints if desired.

`createApi` better types

10 Feb 04:56
f4d3181
Compare
Choose a tag to compare
feat(createApi): better types

`createApi().[method]` has better type support for inferring `ctx`
properties.

```ts
import { createApi } from 'saga-query';

interface Props { id: string }
interface Success { result: string }
interface Err { message: string }

const api = createApi();

const fetchUser = api.get<Props, Success, Err>(
    '/users/:id',
    function*(ctx, next) {
        // will be set to `Props`
        ctx.payload;

        yield next();

        if (ctx.json.ok) {
            // will be set to `Success`
            ctx.json.data;
        } else {
            // will be set to `Err`
            ctx.json.data;
        }
    },
);

dispatch(fetchUser({ id: '1' }));
```

createApi endpoints support arrays for names

09 Feb 14:34
ed3f292
Compare
Choose a tag to compare
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.

`useCache` now calls `useQuery`

07 Feb 04:50
67b11e1
Compare
Choose a tag to compare

This is a breaking change before useCache previously used useApi which meant that the end-user had to call useApi().trigger for the action to be dispatched. Now it is handled automatically.

We also added tsdocs to many of our public functions.

`customKey` middleware and new `createKey` algo

06 Feb 18:37
3f48591
Compare
Choose a tag to compare

This releases adds a new middleware customKey which is loaded into the requestMonitor middleware. The benefit of this middleware is users can now override the auto-generated ctx.key inside their middleware:

const fetchUsers = api.create('/users', function*(ctx, next) {
  ctx.key = 'fetch-users-key';
  yield next();
})

ctx.key is used for automatic caching.

We also modified the algorithm for generating the key automatically. Instead of a base64 encoding we are now performing a hash (pulled from https://gist.github.com/iperelivskiy/4110988).

export createKey and selectDataByName

22 Nov 18:43
babad07
Compare
Choose a tag to compare

Two new functions are exported:

  • createKey which will create a key based on name and payload. This is the function we use to create ctx.key` which is what we use to set loaders as well as the key for caching data
  • selectDataByName which is a selector to grab cache data by name and payload

revert esm build

16 Nov 16:20
953ccfb
Compare
Choose a tag to compare
v5.0.8

revert build system (#21)

send src to pkg

16 Nov 15:34
1890017
Compare
Choose a tag to compare
v5.0.7

send src/ to npm pacakge