asmer před 3 měsíci
rodič
revize
a0f28faf3e
1 změnil soubory, kde provedl 11 přidání a 5 odebrání
  1. 11 5
      src/lib/pub/query/index.ts

+ 11 - 5
src/lib/pub/query/index.ts

@@ -29,6 +29,7 @@ const defaultOptions:CreateQueryPubOptions = {
 
 export default (options:CreateQueryPubOptions) => {
     const queryPub = createPub({queries: {}, mutations: {}})
+    const currentPromises = {queries: {}, mutations: {}}
 
     options = {...defaultOptions, ...options}
 
@@ -41,14 +42,19 @@ export default (options:CreateQueryPubOptions) => {
             }
 
             const query = (...args) => {
-                if (isMutation && (!options.avoidRepeatInProgress || queryPub.mutations?.[promiseName]?.status !== 'PENDING')){
-                    queryPub.mutations[promiseName] = {status: 'PENDING'}
-                    return forceQuery(...args).then(payload => queryPub.mutations[promiseName] = {status: 'FULFILLED', payload},
-                                                    error   => queryPub.mutations[promiseName] = {status: 'REJECTED', error})
+                if (isMutation){
+                    if (options.avoidRepeatInProgress && queryPub.mutations?.[promiseName]?.status === 'PENDING'){
+                        return currentPromises.mutations[promiseName]
+                    }
+                    else {
+                        queryPub.mutations[promiseName] = {status: 'PENDING'}
+                        return currentPromises.mutations[promiseName] = forceQuery(...args).then(payload => queryPub.mutations[promiseName] = {status: 'FULFILLED', payload},
+                                                                                                 error   => queryPub.mutations[promiseName] = {status: 'REJECTED', error})
+                    }
                 }
                 if (!isMutation){
                     const stringifiedArgs = JSON.stringify(args)
-                    queryPub[promiseName][stringifiedArgs]
+                    queryPub.queries[promiseName][stringifiedArgs]
                 }
             }
             return {forceQuery, query}