@aochuang/common 1.0.142 → 1.0.143

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils/util.js +14 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aochuang/common",
3
- "version": "1.0.142",
3
+ "version": "1.0.143",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
package/utils/util.js CHANGED
@@ -221,6 +221,9 @@ export function createThrottleRequest (requestFn, idField = 'id') {
221
221
  let loadMap = {}
222
222
  let timer = null
223
223
  return (id) => {
224
+ if (cacheMap[id]) {
225
+ return cacheMap[id]
226
+ }
224
227
  const ps = createPromise()
225
228
  cacheMap[id] = ps
226
229
  loadMap[id] = true
@@ -231,12 +234,15 @@ export function createThrottleRequest (requestFn, idField = 'id') {
231
234
  requestFn(keys).then(rs => {
232
235
  if (rs && rs.length) {
233
236
  rs.forEach(v => {
234
- cacheMap[v[idField]]._execed = true
235
- cacheMap[v[idField]].resolve(v)
237
+ const cacheId = v[idField]
238
+ if (cacheMap[cacheId]) {
239
+ cacheMap[cacheId]._execed = true
240
+ cacheMap[cacheId].resolve(v)
241
+ }
236
242
  })
237
243
  }
238
244
  keys.forEach(id => {
239
- if (!cacheMap[id]._execed) {
245
+ if (cacheMap[id] && !cacheMap[id]._execed) {
240
246
  // 如果没有返回表示没有找到数据
241
247
  cacheMap[id].reject(new Error('未找到数据'))
242
248
  }
@@ -244,8 +250,10 @@ export function createThrottleRequest (requestFn, idField = 'id') {
244
250
  return rs
245
251
  }, err => {
246
252
  keys.forEach(id => {
247
- cacheMap[id]._execed = true
248
- cacheMap[id].reject(err)
253
+ if (cacheMap[id]) {
254
+ cacheMap[id]._execed = true
255
+ cacheMap[id].reject(err)
256
+ }
249
257
  })
250
258
  }).finally(() => {
251
259
  cacheMap = {}
@@ -424,4 +432,4 @@ export const retryRequest = (() => {
424
432
  }
425
433
  }
426
434
  }
427
- })()
435
+ })()