Explorar el Código

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

asmer hace 3 meses
padre
commit
83c7d6e185
Se han modificado 1 ficheros con 15 adiciones y 13 borrados
  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')}`