Skip to content

Commit edfdb1d

Browse files
committed
Don't recreate proxies willy nilly
1 parent 9047b25 commit edfdb1d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/index.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class SDK<Endpoints extends DeepAsyncFnRecord<Endpoints>> {
117117
return getNextGetSDKQueryKey([]);
118118
})();
119119

120-
useEndpoint(): TypedUseSDK<Endpoints> {
120+
private useEndpointProxy = (() => {
121121
const getNextUseEndpoint = (p: { path: string[] }): any => {
122122
return new Proxy(() => {}, {
123123
apply: (__, ___, args) => {
@@ -157,9 +157,13 @@ class SDK<Endpoints extends DeepAsyncFnRecord<Endpoints>> {
157157
};
158158

159159
return getNextUseEndpoint({ path: [] });
160+
})();
161+
162+
useEndpoint(): TypedUseSDK<Endpoints> {
163+
return this.useEndpointProxy;
160164
}
161165

162-
useInfiniteEndpoint(): TypedUseInfiniteSDK<Endpoints> {
166+
private useInfiniteEndpointProxy = (() => {
163167
const getNextUseInfiniteEndpoint = (p: { path: string[] }): any => {
164168
return new Proxy(() => {}, {
165169
apply: (__, ___, args) => {
@@ -200,8 +204,13 @@ class SDK<Endpoints extends DeepAsyncFnRecord<Endpoints>> {
200204
};
201205

202206
return getNextUseInfiniteEndpoint({ path: [] });
207+
})();
208+
209+
useInfiniteEndpoint(): TypedUseInfiniteSDK<Endpoints> {
210+
return this.useInfiniteEndpointProxy;
203211
}
204-
useMutationEndpoint(): TypedUseSDKMutation<Endpoints> {
212+
213+
private useMutationEndpointProxy = (() => {
205214
const getNextUseMutation = (p: { path: string[] }): any => {
206215
return new Proxy(() => {}, {
207216
apply: (__, ___, args) => {
@@ -239,6 +248,10 @@ class SDK<Endpoints extends DeepAsyncFnRecord<Endpoints>> {
239248
};
240249

241250
return getNextUseMutation({ path: [] });
251+
})();
252+
253+
useMutationEndpoint(): TypedUseSDKMutation<Endpoints> {
254+
return this.useMutationEndpointProxy;
242255
}
243256
}
244257

0 commit comments

Comments
 (0)