From e4751d9cd0ee26567d7632ea4707ca181901ff89 Mon Sep 17 00:00:00 2001 From: Nathaniel Tucker Date: Mon, 22 Jul 2024 13:15:04 +0200 Subject: [PATCH] enhance: NetworkManager constructor uses keyword args --- .changeset/real-days-camp.md | 18 ++++++++++++++++++ docs/core/getting-started/debugging.md | 2 +- docs/rest/api/Collection.md | 4 ++++ examples/todo-app/src/RootProvider.tsx | 6 +----- packages/core/src/manager/NetworkManager.ts | 2 +- .../src/manager/__tests__/networkManager.ts | 2 +- 6 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 .changeset/real-days-camp.md diff --git a/.changeset/real-days-camp.md b/.changeset/real-days-camp.md new file mode 100644 index 000000000000..944ce11bc8ee --- /dev/null +++ b/.changeset/real-days-camp.md @@ -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 }); +``` \ No newline at end of file diff --git a/docs/core/getting-started/debugging.md b/docs/core/getting-started/debugging.md index 3cab4bf02047..233b60529cc6 100644 --- a/docs/core/getting-started/debugging.md +++ b/docs/core/getting-started/debugging.md @@ -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 diff --git a/docs/rest/api/Collection.md b/docs/rest/api/Collection.md index c3b80caa977f..d810fab5ecbc 100644 --- a/docs/rest/api/Collection.md +++ b/docs/rest/api/Collection.md @@ -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 }), }); ``` @@ -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/, }), }); @@ -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'], }), }); diff --git a/examples/todo-app/src/RootProvider.tsx b/examples/todo-app/src/RootProvider.tsx index b9de2b8cfb5f..7f3b455e79af 100644 --- a/examples/todo-app/src/RootProvider.tsx +++ b/examples/todo-app/src/RootProvider.tsx @@ -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 ( diff --git a/packages/core/src/manager/NetworkManager.ts b/packages/core/src/manager/NetworkManager.ts index c98e07539180..4edfa215ead2 100644 --- a/packages/core/src/manager/NetworkManager.ts +++ b/packages/core/src/manager/NetworkManager.ts @@ -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; diff --git a/packages/core/src/manager/__tests__/networkManager.ts b/packages/core/src/manager/__tests__/networkManager.ts index 26bd72264ca2..1817fdf7368d 100644 --- a/packages/core/src/manager/__tests__/networkManager.ts +++ b/packages/core/src/manager/__tests__/networkManager.ts @@ -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(() => {