Browse Source

pub-query checks: mutations and mutations refresh

asmer 3 months ago
parent
commit
70a0320977
2 changed files with 8 additions and 8 deletions
  1. 5 5
      src/App.tsx
  2. 3 3
      src/lib/pub/query/index.ts

+ 5 - 5
src/App.tsx

@@ -39,7 +39,7 @@ const {queryPub, createQuery, withQueryFunc} = createQueryPub({
 //queryPub.subscribe(() => console.log(JSON.stringify(queryPub.queries.user, null, 4)))
 
 const {useGoodsQuery} = createQuery({promiseName: 'goods',
-                                     cacheTagFunc: (payload) => payload.data.GoodFind.map(good => ({type: 'Good', id: good._id}))})
+                                     cacheTagsFunc: (payload) => payload.data.GoodFind.map(good => ({type: 'Good', id: good._id}))})
 
 //const {useUserQuery}  = createQuery({
     //promiseName: 'user',
@@ -50,7 +50,7 @@ const {useGoodsQuery} = createQuery({promiseName: 'goods',
             //}
         //}
     //`],
-    //cacheTagFunc: ({data: {UserFindOne: {_id}}}) => ({_id, type: 'User'})
+    //cacheTagsFunc: ({data: {UserFindOne: {_id}}}) => ({_id, type: 'User'})
 //})
 //const userState = useUserQuery({query: JSON.stringify([{_id: '667ff0da2232120c7c871f7c'}])})
 
@@ -63,7 +63,7 @@ const {useGoodsQuery} = createQuery({promiseName: 'goods',
     //{query: JSON.stringify([{_id}])}
 //))({
     //promiseName: 'user',
-    //cacheTagFunc: ({data: {UserFindOne: {_id}}}) => ({_id, type: 'User'})
+    //cacheTagsFunc: ({data: {UserFindOne: {_id}}}) => ({_id, type: 'User'})
 //})
 
 
@@ -76,7 +76,7 @@ const {useUserQuery}  = createQuery({
             }
         }
     `, {query: JSON.stringify([{_id}])}],
-    cacheTagFunc: ({data: {UserFindOne: {_id}}}) => [{_id, type: 'User'}]
+    cacheTagsFunc: ({data: {UserFindOne: {_id}}}) => [{_id, type: 'User'}]
 })
 
 const {useUserMutation} = createQuery({
@@ -89,7 +89,7 @@ const {useUserMutation} = createQuery({
             }
         }`,
         {_id, nick}],
-    cacheTagFunc: ({data: {UserUpsert: {_id}}}) => [{_id, type: 'User'}]
+    cacheTagsFunc: ({data: {UserUpsert: {_id}}}) => [{_id, type: 'User'}]
 })
 
 const EditNick = () => {

+ 3 - 3
src/lib/pub/query/index.ts

@@ -37,7 +37,7 @@ export default (options:CreateQueryPubOptions) => {
     options = {...defaultOptions, ...options}
 
     const withQueryFunc = (queryFunc?: QueryFuncType):Function => {
-        return ({promiseName, isMutation, cacheTagFunc, args=[]}) => {
+        return ({promiseName, isMutation, cacheTagsFunc, args=[]}) => {
             const qF = queryFunc || options.queryFunc
             const defaultArgs = args
 
@@ -82,7 +82,7 @@ export default (options:CreateQueryPubOptions) => {
                         if (!queryPub.mutations[promiseName].refreshing){
                             queryPub.mutations[promiseName].refreshing = true
                         }
-                        return currentPromises.mutations[promiseName] = makeQuery(...args).then(payload => queryPub.mutations[promiseName] = (invalidateTags(cacheTagFunc && cacheTagFunc(payload)),{status: 'FULFILLED', payload}),
+                        return currentPromises.mutations[promiseName] = makeQuery(...args).then(payload => queryPub.mutations[promiseName] = (invalidateTags(cacheTagsFunc && cacheTagsFunc(payload)),{status: 'FULFILLED', payload}),
                                                                                                 error   => queryPub.mutations[promiseName] = {status: 'REJECTED', error})
                     }
                 }
@@ -136,7 +136,7 @@ export default (options:CreateQueryPubOptions) => {
                                                                                                                                                             status: 'FULFILLED', 
                                                                                                                                                             payload, 
                                                                                                                                                             timeStamp: Date.now(), 
-                                                                                                                                                            cacheTags: cacheTagFunc(payload),
+                                                                                                                                                            cacheTags: cacheTagsFunc && cacheTagsFunc(payload),
                                                                                                                                                             timeoutId: options.cacheTimeout && options.forceRefreshAfterTimeout ? setTimeout(() =>forceQuery(...args), options.cacheTimeout) : null
                                                                                                                                                         },
                                                                                            error   => queryPub.queries[promiseName][stringifiedArgs] = {