Skip to content

Commit

Permalink
enhance: NetworkManager constructor uses keyword args
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Jul 22, 2024
1 parent 8bdcc14 commit e4751d9
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
18 changes: 18 additions & 0 deletions .changeset/real-days-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@data-client/core': patch
'@data-client/react': patch
---

NetworkManager constructor uses keyword args

#### Before

```ts
new NetworkManager(42, 7);
```

#### After

```ts
new NetworkManager({ dataExpiryLength: 42, errorExpiryLength: 7 });
```
2 changes: 1 addition & 1 deletion docs/core/getting-started/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ straightforward as each change is traceable and descriptive.
}}
/>

> [More about control flow](../api/Manager#control-flow)
> [More about control flow](../concepts/managers.md)
## State Inspection

Expand Down
4 changes: 4 additions & 0 deletions docs/rest/api/Collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,11 @@ const getPosts = new RestEndpoint({
path: '/:group/posts',
searchParams: {} as { orderBy?: string; author?: string },
schema: new schema.Collection([Post], {
// highlight-start
nonFilterArgumentKeys(key) {
return key === 'orderBy';
},
// highlight-end
}),
});
```
Expand All @@ -273,6 +275,7 @@ const getPosts = new RestEndpoint({
path: '/:group/posts',
searchParams: {} as { orderBy?: string; author?: string },
schema: new schema.Collection([Post], {
// highlight-next-line
nonFilterArgumentKeys: /orderBy/,
}),
});
Expand All @@ -283,6 +286,7 @@ const getPosts = new RestEndpoint({
path: '/:group/posts',
searchParams: {} as { orderBy?: string; author?: string },
schema: new schema.Collection([Post], {
// highlight-next-line
nonFilterArgumentKeys: ['orderBy'],
}),
});
Expand Down
6 changes: 1 addition & 5 deletions examples/todo-app/src/RootProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
DataProvider,
AsyncBoundary,
ProviderProps,
} from '@data-client/react';
import { DataProvider, AsyncBoundary, ProviderProps } from '@data-client/react';

export default function RootProvider({ children, ...rest }: Props) {
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/manager/NetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class NetworkManager implements Manager {
protected controller: Controller = new Controller();
declare cleanupDate?: number;

constructor(dataExpiryLength = 60000, errorExpiryLength = 1000) {
constructor({ dataExpiryLength = 60000, errorExpiryLength = 1000 } = {}) {
this.dataExpiryLength = dataExpiryLength;
this.errorExpiryLength = errorExpiryLength;

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/manager/__tests__/networkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('NetworkManager', () => {
let NM: NetworkManager;
let middleware: Middleware;
beforeEach(() => {
NM = new NetworkManager(42, 7);
NM = new NetworkManager({ dataExpiryLength: 42, errorExpiryLength: 7 });
middleware = NM.getMiddleware();
});
afterEach(() => {
Expand Down

0 comments on commit e4751d9

Please sign in to comment.