|
@@ -29,6 +29,7 @@ const defaultOptions:CreateQueryPubOptions = {
|
|
|
|
|
|
export default (options:CreateQueryPubOptions) => {
|
|
export default (options:CreateQueryPubOptions) => {
|
|
const queryPub = createPub({queries: {}, mutations: {}})
|
|
const queryPub = createPub({queries: {}, mutations: {}})
|
|
|
|
+ const currentPromises = {queries: {}, mutations: {}}
|
|
|
|
|
|
options = {...defaultOptions, ...options}
|
|
options = {...defaultOptions, ...options}
|
|
|
|
|
|
@@ -41,14 +42,19 @@ export default (options:CreateQueryPubOptions) => {
|
|
}
|
|
}
|
|
|
|
|
|
const query = (...args) => {
|
|
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){
|
|
if (!isMutation){
|
|
const stringifiedArgs = JSON.stringify(args)
|
|
const stringifiedArgs = JSON.stringify(args)
|
|
- queryPub[promiseName][stringifiedArgs]
|
|
|
|
|
|
+ queryPub.queries[promiseName][stringifiedArgs]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return {forceQuery, query}
|
|
return {forceQuery, query}
|