소스 검색

refactor 328a7af9: use a unique moniker

tophf 2 년 전
부모
커밋
1f540d2dd4
3개의 변경된 파일6개의 추가작업 그리고 4개의 파일을 삭제
  1. 1 1
      src/background/utils/storage-fetch.js
  2. 3 1
      src/background/utils/storage.js
  3. 2 2
      src/types.d.ts

+ 1 - 1
src/background/utils/storage-fetch.js

@@ -43,7 +43,7 @@ function cacheOrFetch(handlers = {}) {
       if (res) {
         const result = transform ? await transform(res, ...args) : res.data;
         await this.setOne(url, result);
-        if (options === true) {
+        if (options === 'res') {
           return result;
         }
       }

+ 3 - 1
src/background/utils/storage.js

@@ -32,7 +32,9 @@ class StorageArea {
   async getOne(id, fetchMissing) {
     const key = this.toKey(id);
     const {
-      [key]: val = fetchMissing ? await this.fetch(id, true).catch(console.warn) : undefined,
+      [key]: val = fetchMissing
+        ? await this.fetch(id, 'res').catch(console.warn)
+        : undefined,
     } = await api.get([key]);
     return val;
   }

+ 2 - 2
src/types.d.ts

@@ -328,8 +328,8 @@ declare type VMSearchOptions = {
 /** Throws on error */
 declare type VMStorageFetch = (
   url: string,
-  /** Resolves with the result if true, `undefined` otherwise */
-  options?: VMReq.Options | true,
+  /** 'res' makes the function resolve with the result */
+  options?: VMReq.Options | 'res',
   check?: (...args) => void // throws on error
 ) => Promise<void>