Skip to content

Commit

Permalink
enhance: Get rid of fetch action.meta.nm (#3139)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Jul 8, 2024
1 parent ee509fb commit 9df0f7c
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 38 deletions.
6 changes: 6 additions & 0 deletions .changeset/wild-lobsters-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@data-client/core': minor
'@data-client/react': patch
---

Get rid of fetch action.meta.nm. This is not used anywhere.
2 changes: 0 additions & 2 deletions packages/core/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ export interface FetchMeta<A extends readonly any[] = readonly any[]> {
reject: (reason?: any) => void;
promise: PromiseLike<any>;
createdAt: number;
// indicates whether network manager processed it
nm?: boolean;
}

export interface FetchAction<E extends EndpointAndUpdate<E> = EndpointDefault> {
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 @@ -26,7 +26,6 @@ export default function createFetch<
reject,
promise,
createdAt: Date.now(),
nm: false,
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ exports[`PollingSubscription fresh data should call after period 1`] = `
"meta": {
"args": [],
"key": "test.com",
"nm": false,
"promise": Promise {},
"reject": [Function],
"resolve": [Function],
Expand All @@ -31,7 +30,6 @@ exports[`PollingSubscription fresh data should call after period 2`] = `
"meta": {
"args": [],
"key": "test.com",
"nm": false,
"promise": Promise {},
"reject": [Function],
"resolve": [Function],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ exports[`useController.fetch should dispatch an action that fetches a create 1`]
},
],
"key": "POST http://test.com/article-cooler",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand All @@ -64,7 +63,6 @@ exports[`useController.fetch should dispatch an action that fetches a full updat
},
],
"key": "PUT http://test.com/article-cooler/1",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand All @@ -86,7 +84,6 @@ exports[`useController.fetch should dispatch an action that fetches a partial up
},
],
"key": "PATCH http://test.com/article-cooler/1",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand All @@ -105,7 +102,6 @@ exports[`useController.fetch should dispatch an action with updater in the meta
},
],
"key": "POST http://test.com/article-cooler",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand All @@ -124,7 +120,6 @@ exports[`useController.fetch should refresh get details 1`] = `
},
],
"key": "GET http://test.com/article-cooler/1",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ exports[`useDLE should dispatch singles 1`] = `
},
],
"key": "GET http://test.com/article-cooler/5",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand All @@ -29,7 +28,6 @@ exports[`useDLE should dispatch with fetch shape defined dataExpiryLength 1`] =
},
],
"key": "GET http://test.com/article-static/5",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand All @@ -48,7 +46,6 @@ exports[`useDLE should dispatch with fetch shape defined errorExpiryLength 1`] =
},
],
"key": "GET http://test.com/article-static/5",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand All @@ -67,7 +64,6 @@ exports[`useDLE should dispatch with resource defined dataExpiryLength 1`] = `
},
],
"key": "GET http://test.com/article-static/5",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ exports[`useFetch should dispatch singles 1`] = `
},
],
"key": "GET http://test.com/article-cooler/5",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand All @@ -29,7 +28,6 @@ exports[`useFetch should dispatch with fetch shape defined dataExpiryLength 1`]
},
],
"key": "GET http://test.com/article-static/5",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand All @@ -48,7 +46,6 @@ exports[`useFetch should dispatch with fetch shape defined errorExpiryLength 1`]
},
],
"key": "GET http://test.com/article-static/5",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand All @@ -67,7 +64,6 @@ exports[`useFetch should dispatch with resource defined dataExpiryLength 1`] = `
},
],
"key": "GET http://test.com/article-static/5",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ exports[`useFetch should dispatch singles 1`] = `
},
],
"key": "GET http://test.com/article-cooler/5",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand All @@ -29,7 +28,6 @@ exports[`useFetch should dispatch with fetch shape defined dataExpiryLength 1`]
},
],
"key": "GET http://test.com/article-static/5",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand All @@ -48,7 +46,6 @@ exports[`useFetch should dispatch with fetch shape defined errorExpiryLength 1`]
},
],
"key": "GET http://test.com/article-static/5",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand All @@ -67,7 +64,6 @@ exports[`useFetch should dispatch with resource defined dataExpiryLength 1`] = `
},
],
"key": "GET http://test.com/article-static/5",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ exports[`useSuspense() should dispatch an action that fetches 1`] = `
},
],
"key": "GET http://test.com/article-cooler/5",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ exports[`useSuspense() should dispatch an action that fetches 1`] = `
},
],
"key": "GET http://test.com/article-cooler/5",
"nm": false,
"reject": [Function],
"resolve": [Function],
},
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/server/createPersistedStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export default function createPersistedStore(
) {
const controller = new Controller();
managers = managers ?? [new ReactNetworkManager()];
const nm: NetworkManager = managers.find(
const networkManager: NetworkManager = managers.find(
m => m instanceof NetworkManager,
) as any;
if (nm === undefined)
if (networkManager === undefined)
throw new Error('managers must include a NetworkManager');
const reducer = createReducer(controller);
const enhancer = applyMiddleware(
Expand All @@ -43,7 +43,7 @@ export default function createPersistedStore(
const getState = () => selector(store.getState());
let firstRender = true;
function useReadyCacheState(): State<unknown> {
const inFlightFetches = nm.allSettled();
const inFlightFetches = networkManager.allSettled();
if (inFlightFetches) {
firstRender = false;
throw inFlightFetches;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import SSRDataProvider from '../../SSRDataProvider.js';
export default function createPersistedStore(managers?: Manager[]) {
const controller = new Controller();
managers = managers ?? [new ReactNetworkManager()];
const nm: NetworkManager = managers.find(
const networkManager: NetworkManager = managers.find(
m => m instanceof NetworkManager,
) as any;
if (nm === undefined)
if (networkManager === undefined)
throw new Error('managers must include a NetworkManager');
const reducer = createReducer(controller);
const enhancer = applyMiddleware(
Expand All @@ -44,15 +44,15 @@ export default function createPersistedStore(managers?: Manager[]) {
let firstRender = true;
// eslint-disable-next-line no-constant-condition
while (true) {
const inFlightFetches = nm.allSettled();
const inFlightFetches = networkManager.allSettled();
if (inFlightFetches) {
firstRender = false;
await inFlightFetches;
continue;
}
if (firstRender) {
firstRender = false;
// TODO: instead of waiting 10ms - see if we can wait until next part of react is streamed and race with nm getting new fetches
// TODO: instead of waiting 10ms - see if we can wait until next part of react is streamed and race with networkManager getting new fetches
await new Promise(resolve => setTimeout(resolve, 10));
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/ssr/src/createPersistedStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const { createReducer, initialState, applyManager } = __INTERNAL__;
export default function createPersistedStore(managers?: Manager[]) {
const controller = new Controller();
managers = managers ?? [new NetworkManager()];
const nm: NetworkManager = managers.find(
const networkManager: NetworkManager = managers.find(
m => m instanceof NetworkManager,
) as any;
if (nm === undefined)
if (networkManager === undefined)
throw new Error('managers must include a NetworkManager');
const reducer = createReducer(controller);
const enhancer = applyMiddleware(
Expand All @@ -38,7 +38,7 @@ export default function createPersistedStore(managers?: Manager[]) {
const getState = () => selector(store.getState());
let firstRender = true;
function useReadyCacheState(): State<unknown> {
const inFlightFetches = nm.allSettled();
const inFlightFetches = networkManager.allSettled();
if (inFlightFetches) {
firstRender = false;
throw inFlightFetches;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const { createReducer, initialState, applyManager } = __INTERNAL__;
export default function createPersistedStore(managers?: Manager[]) {
const controller = new Controller();
managers = managers ?? [new NetworkManager()];
const nm: NetworkManager = managers.find(
const networkManager: NetworkManager = managers.find(
m => m instanceof NetworkManager,
) as any;
if (nm === undefined)
if (networkManager === undefined)
throw new Error('managers must include a NetworkManager');
const reducer = createReducer(controller);
const enhancer = applyMiddleware(
Expand All @@ -41,15 +41,15 @@ export default function createPersistedStore(managers?: Manager[]) {
let firstRender = true;
// eslint-disable-next-line no-constant-condition
while (true) {
const inFlightFetches = nm.allSettled();
const inFlightFetches = networkManager.allSettled();
if (inFlightFetches) {
firstRender = false;
await inFlightFetches;
continue;
}
if (firstRender) {
firstRender = false;
// TODO: instead of waiting 10ms - see if we can wait until next part of react is streamed and race with nm getting new fetches
// TODO: instead of waiting 10ms - see if we can wait until next part of react is streamed and race with networkManager getting new fetches
await new Promise(resolve => setTimeout(resolve, 10));
continue;
}
Expand Down

0 comments on commit 9df0f7c

Please sign in to comment.