Skip to content

Commit

Permalink
enhance: Remove throttle from fetch action (#3138)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Jul 8, 2024
1 parent 2ad1811 commit ee509fb
Show file tree
Hide file tree
Showing 13 changed files with 11 additions and 28 deletions.
7 changes: 7 additions & 0 deletions .changeset/healthy-buses-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@data-client/core': minor
---

Remove throttle from FETCH_TYPE action

BREAKING CHANGE: action.meta.throttle -> !action.endpoint.sideEffect
1 change: 0 additions & 1 deletion packages/core/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export type SetResponseAction<
export interface FetchMeta<A extends readonly any[] = readonly any[]> {
args: A;
key: string;
throttle: boolean;
resolve: (value?: any | PromiseLike<any>) => void;
reject: (reason?: any) => void;
promise: PromiseLike<any>;
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/controller/createFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default function createFetch<
const meta: FetchMeta<typeof args> = {
args,
key,
throttle: !endpoint.sideEffect,
resolve,
reject,
promise,
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/manager/NetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,13 @@ export default class NetworkManager implements Manager {
* Will then start a promise for a key and potentially start the network
* fetch.
*
* Uses throttle only when instructed by action meta. This is valuable
* Uses throttle endpoints without sideEffects. This is valuable
* for ensures mutation requests always go through.
*/
protected handleFetch(action: FetchAction) {
const fetch = action.payload;
const { key, throttle, resolve, reject, createdAt } = action.meta;
const { key, resolve, reject, createdAt } = action.meta;
const throttle = !action.endpoint.sideEffect;

const deferedFetch = () => {
let promise = fetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ exports[`PollingSubscription fresh data should call after period 1`] = `
"promise": Promise {},
"reject": [Function],
"resolve": [Function],
"throttle": true,
},
"payload": [Function],
"type": "rdc/fetch",
Expand All @@ -36,7 +35,6 @@ exports[`PollingSubscription fresh data should call after period 2`] = `
"promise": Promise {},
"reject": [Function],
"resolve": [Function],
"throttle": true,
},
"payload": [Function],
"type": "rdc/fetch",
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/state/__tests__/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,6 @@ describe('reducer', () => {
meta: {
args: [{ id: 5 }],
key: ArticleResource.get.url({ id: 5 }),
throttle: true,
reject: (v: any) => null,
resolve: (v: any) => null,
promise: new Promise((v: any) => null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ exports[`useController.fetch should dispatch an action that fetches a create 1`]
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": false,
},
"payload": [Function],
"type": "rdc/fetch",
Expand All @@ -68,7 +67,6 @@ exports[`useController.fetch should dispatch an action that fetches a full updat
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": false,
},
"payload": [Function],
"type": "rdc/fetch",
Expand All @@ -91,7 +89,6 @@ exports[`useController.fetch should dispatch an action that fetches a partial up
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": false,
},
"payload": [Function],
"type": "rdc/fetch",
Expand All @@ -111,7 +108,6 @@ exports[`useController.fetch should dispatch an action with updater in the meta
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": false,
},
"payload": [Function],
"type": "rdc/fetch",
Expand All @@ -131,7 +127,6 @@ exports[`useController.fetch should refresh get details 1`] = `
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": true,
},
"payload": [Function],
"type": "rdc/fetch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ exports[`useDLE should dispatch singles 1`] = `
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": true,
},
"payload": [Function],
"type": "rdc/fetch",
Expand All @@ -33,7 +32,6 @@ exports[`useDLE should dispatch with fetch shape defined dataExpiryLength 1`] =
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": true,
},
"payload": [Function],
"type": "rdc/fetch",
Expand All @@ -53,7 +51,6 @@ exports[`useDLE should dispatch with fetch shape defined errorExpiryLength 1`] =
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": true,
},
"payload": [Function],
"type": "rdc/fetch",
Expand All @@ -73,7 +70,6 @@ exports[`useDLE should dispatch with resource defined dataExpiryLength 1`] = `
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": true,
},
"payload": [Function],
"type": "rdc/fetch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ exports[`useFetch should dispatch singles 1`] = `
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": true,
},
"payload": [Function],
"type": "rdc/fetch",
Expand All @@ -33,7 +32,6 @@ exports[`useFetch should dispatch with fetch shape defined dataExpiryLength 1`]
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": true,
},
"payload": [Function],
"type": "rdc/fetch",
Expand All @@ -53,7 +51,6 @@ exports[`useFetch should dispatch with fetch shape defined errorExpiryLength 1`]
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": true,
},
"payload": [Function],
"type": "rdc/fetch",
Expand All @@ -73,7 +70,6 @@ exports[`useFetch should dispatch with resource defined dataExpiryLength 1`] = `
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": true,
},
"payload": [Function],
"type": "rdc/fetch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ exports[`useFetch should dispatch singles 1`] = `
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": true,
},
"payload": [Function],
"type": "rdc/fetch",
Expand All @@ -33,7 +32,6 @@ exports[`useFetch should dispatch with fetch shape defined dataExpiryLength 1`]
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": true,
},
"payload": [Function],
"type": "rdc/fetch",
Expand All @@ -53,7 +51,6 @@ exports[`useFetch should dispatch with fetch shape defined errorExpiryLength 1`]
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": true,
},
"payload": [Function],
"type": "rdc/fetch",
Expand All @@ -73,7 +70,6 @@ exports[`useFetch should dispatch with resource defined dataExpiryLength 1`] = `
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": true,
},
"payload": [Function],
"type": "rdc/fetch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ exports[`useSuspense() should dispatch an action that fetches 1`] = `
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": true,
},
"payload": [Function],
"type": "rdc/fetch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ exports[`useSuspense() should dispatch an action that fetches 1`] = `
"nm": false,
"reject": [Function],
"resolve": [Function],
"throttle": true,
},
"payload": [Function],
"type": "rdc/fetch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ type SetResponseAction<E extends EndpointAndUpdate<E> = EndpointDefault> = SetRe
interface FetchMeta<A extends readonly any[] = readonly any[]> {
args: A;
key: string;
throttle: boolean;
resolve: (value?: any | PromiseLike<any>) => void;
reject: (reason?: any) => void;
promise: PromiseLike<any>;
Expand Down Expand Up @@ -658,7 +657,7 @@ declare class NetworkManager implements Manager {
* Will then start a promise for a key and potentially start the network
* fetch.
*
* Uses throttle only when instructed by action meta. This is valuable
* Uses throttle endpoints without sideEffects. This is valuable
* for ensures mutation requests always go through.
*/
protected handleFetch(action: FetchAction): Promise<any>;
Expand Down

0 comments on commit ee509fb

Please sign in to comment.