@@ -24,7 +24,7 @@ import type { IrcClient } from '$lib/irc/ircClient.svelte';
24
24
import type { ReduxError } from '$lib/state/reduxError' ;
25
25
26
26
/**
27
- * GitHub API object that enables the declaration and usage of endpoints
27
+ * Backend API object that enables the declaration and usage of endpoints
28
28
* colocated with the feature they support.
29
29
*/
30
30
export type BackendApi = ReturnType < typeof createBackendApi > ;
@@ -78,9 +78,8 @@ export class ClientState {
78
78
posthog : PostHogWrapper
79
79
) {
80
80
const butlerMod = butlerModule ( {
81
- // Reactive loop without nested function.
82
- // TODO: Can it be done without nesting?
83
- getState : ( ) => ( ) => this . rootState as any as RootState < any , any , any > ,
81
+ // Returns a function that returns the current state (required by butlerModule API)
82
+ getState : ( ) => this . rootState as unknown as RootState < any , any , any > ,
84
83
getDispatch : ( ) => this . dispatch ,
85
84
posthog
86
85
} ) ;
@@ -177,7 +176,6 @@ function createStore(params: {
177
176
}
178
177
} ) ;
179
178
180
- // persistStore(store);
181
179
return { store, reducer } ;
182
180
}
183
181
@@ -207,8 +205,8 @@ function createBackendApi(butlerMod: ReturnType<typeof butlerModule>) {
207
205
}
208
206
209
207
// Default cache expiration for unused items is 60 seconds. This is too little
210
- // for forge data.
211
- const KEEP_UNUSED_SECONDS = 24 * 60 * 60 ;
208
+ // for forge data, so we keep forge data cached for 24 hours .
209
+ const FORGE_CACHE_TTL_SECONDS = 24 * 60 * 60 ; // 24 hours
212
210
213
211
// Fake base query that allows us to use the same error type when the query
214
212
// definitions only use `queryFn` instead of `query`.
@@ -217,22 +215,25 @@ const fakeBaseQuery: BaseQueryFn = () => {
217
215
return { data : undefined } as QueryReturnValue < never , ReduxError , any > ;
218
216
} ;
219
217
218
+ // Common API configuration for forge APIs
219
+ const FORGE_API_CONFIG = {
220
+ tagTypes : Object . values ( ReduxTag ) ,
221
+ invalidationBehavior : 'immediately' as const ,
222
+ baseQuery : fakeBaseQuery ,
223
+ refetchOnFocus : true ,
224
+ refetchOnReconnect : true ,
225
+ keepUnusedDataFor : FORGE_CACHE_TTL_SECONDS ,
226
+ endpoints : ( _ : any ) => ( { } )
227
+ } ;
228
+
220
229
export function createGitHubApi ( butlerMod : ReturnType < typeof butlerModule > ) {
221
230
return buildCreateApi (
222
231
coreModule ( ) ,
223
232
butlerMod
224
233
) ( {
225
234
reducerPath : 'github' ,
226
- tagTypes : Object . values ( ReduxTag ) ,
227
- invalidationBehavior : 'immediately' ,
228
- // TODO: This should only be set for backend api.
229
- baseQuery : fakeBaseQuery ,
230
- refetchOnFocus : true ,
231
- refetchOnReconnect : true ,
232
- keepUnusedDataFor : KEEP_UNUSED_SECONDS ,
233
- endpoints : ( _ ) => {
234
- return { } ;
235
- }
235
+ // Using fake base query for forge APIs (GitHub/GitLab) since they use queryFn
236
+ ...FORGE_API_CONFIG
236
237
} ) ;
237
238
}
238
239
@@ -242,15 +243,7 @@ function createGitLabApi(butlerMod: ReturnType<typeof butlerModule>) {
242
243
butlerMod
243
244
) ( {
244
245
reducerPath : 'gitlab' ,
245
- tagTypes : Object . values ( ReduxTag ) ,
246
- invalidationBehavior : 'immediately' ,
247
- // TODO: This should only be set for backend api.
248
- baseQuery : fakeBaseQuery ,
249
- refetchOnFocus : true ,
250
- refetchOnReconnect : true ,
251
- keepUnusedDataFor : KEEP_UNUSED_SECONDS ,
252
- endpoints : ( _ ) => {
253
- return { } ;
254
- }
246
+ // Using fake base query for forge APIs (GitHub/GitLab) since they use queryFn
247
+ ...FORGE_API_CONFIG
255
248
} ) ;
256
249
}
0 commit comments