Pārlūkot izejas kodu

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

asmer 3 mēneši atpakaļ
vecāks
revīzija
83c7d6e185
1 mainītis faili ar 15 papildinājumiem un 13 dzēšanām
  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')}`