Jelajahi Sumber

pub-query checks: cacheTimeout, cacheTags, autorefresh and so. TODO: mutationss

asmer 3 bulan lalu
induk
melakukan
83c7d6e185
1 mengubah file dengan 15 tambahan dan 13 penghapusan
  1. 15 13
      src/lib/pub/query/index.ts

+ 15 - 13
src/lib/pub/query/index.ts

@@ -8,6 +8,7 @@ type CreateQueryPubOptions = {
     cacheTimeout?: number,
     hidePendingOnRefresh?: boolean
     avoidRepeatInProgress?: boolean,
+    forceRefreshAfterTimeout?: boolean,
 }
 
 enum PromiseStatus  {
@@ -103,19 +104,20 @@ export default (options:CreateQueryPubOptions) => {
 
 
 
-                return currentPromises.queries[promiseName][stringifiedArgs] = makeQuery(...args).then(payload => queryPub.queries[promiseName][stringifiedArgs] = {    
-                                                                                                                                                                        status: 'FULFILLED', 
-                                                                                                                                                                        payload, 
-                                                                                                                                                                        timeStamp: Date.now(), 
-                                                                                                                                                                        cacheTags: cacheTagFunc(payload),
-                                                                                                                                                                        timeoutId: options.cacheTimeout ? setTimeout(() =>forceQuery(...args), options.cacheTimeout) : null
-                                                                                                                                                                    },
-                                                                                                       error   => queryPub.queries[promiseName][stringifiedArgs] = {
-                                                                                                                                                                        status: 'REJECTED', 
-                                                                                                                                                                        error, 
-                                                                                                                                                                        timeStamp: Date.now(),
-                                                                                                                                                                        timeoutId: options.cacheTimeout ? setTimeout(() =>forceQuery(...args), options.cacheTimeout) : null
-                                                                                                                                                                    })
+                return currentPromises.queries[promiseName][stringifiedArgs] = makeQuery(...args)
+                                                                                    .then(payload => queryPub.queries[promiseName][stringifiedArgs] = {    
+                                                                                                                                                            status: 'FULFILLED', 
+                                                                                                                                                            payload, 
+                                                                                                                                                            timeStamp: Date.now(), 
+                                                                                                                                                            cacheTags: cacheTagFunc(payload),
+                                                                                                                                                            timeoutId: options.cacheTimeout && options.forceRefreshAfterTimeout ? setTimeout(() =>forceQuery(...args), options.cacheTimeout) : null
+                                                                                                                                                        },
+                                                                                           error   => queryPub.queries[promiseName][stringifiedArgs] = {
+                                                                                                                                                            status: 'REJECTED', 
+                                                                                                                                                            error, 
+                                                                                                                                                            timeStamp: Date.now(),
+                                                                                                                                                            timeoutId: options.cacheTimeout && options.forceRefreshAfterTimeout ? setTimeout(() =>forceQuery(...args), options.cacheTimeout) : null
+                                                                                                                                                        })
             }
 
             const hookName = `use${promiseName[0].toUpperCase() + promiseName.slice(1) + (isMutation ? 'Mutation' : 'Query')}`