create-api-hooks
Advanced tools
Comparing version 0.0.40 to 0.0.41
@@ -21,3 +21,3 @@ /// <reference types="react" /> | ||
*/ | ||
cache?: boolean; | ||
cache?: boolean | 'local' | 'session'; | ||
/** | ||
@@ -24,0 +24,0 @@ * 相同的接口和参数只会请求一次 |
@@ -16,3 +16,3 @@ import { useEffect, useState, useCallback, useRef } from 'react'; | ||
var _b = _a === void 0 ? {} : _a, _c = _b.cache, cache = _c === void 0 ? true : _c, _d = _b.initValue, initValue = _d === void 0 ? {} : _d, params = _b.params, _e = _b.needInit, needInit = _e === void 0 ? true : _e, _f = _b.deepCache, deepCache = _f === void 0 ? false : _f, debounceInterval = _b.debounceInterval; | ||
initValue = cache | ||
initValue = cache === 'local' ? localStorage.getItem(getRequestString(params)) : cache === 'session' ? sessionStorage.getItem(getRequestString(params)) : cache | ||
? createApiHooksConfig.getCacheFn(getRequestString(params)) || initValue | ||
@@ -35,4 +35,10 @@ : initValue; | ||
var requestString = getRequestString(params); | ||
var setCacheFn = createApiHooksConfig.setCacheFn; | ||
var getCacheFn = createApiHooksConfig.getCacheFn; | ||
var setCacheFn = { | ||
local: function (name, value) { return localStorage.setItem(name, value); }, | ||
session: function (name, value) { return sessionStorage.setItem(name, value); }, | ||
}[cache + ''] || createApiHooksConfig.setCacheFn; | ||
var getCacheFn = { | ||
local: function (name) { return localStorage.getItem(name); }, | ||
session: function (name) { return sessionStorage.getItem(name); }, | ||
}[cache + ''] || createApiHooksConfig.getCacheFn; | ||
if ((JSON.stringify(preParams.current) === JSON.stringify(params) && | ||
@@ -39,0 +45,0 @@ !isOutRequest) || |
@@ -20,3 +20,3 @@ 'use strict'; | ||
var _b = _a === void 0 ? {} : _a, _c = _b.cache, cache = _c === void 0 ? true : _c, _d = _b.initValue, initValue = _d === void 0 ? {} : _d, params = _b.params, _e = _b.needInit, needInit = _e === void 0 ? true : _e, _f = _b.deepCache, deepCache = _f === void 0 ? false : _f, debounceInterval = _b.debounceInterval; | ||
initValue = cache | ||
initValue = cache === 'local' ? localStorage.getItem(getRequestString(params)) : cache === 'session' ? sessionStorage.getItem(getRequestString(params)) : cache | ||
? createApiHooksConfig.getCacheFn(getRequestString(params)) || initValue | ||
@@ -39,4 +39,10 @@ : initValue; | ||
var requestString = getRequestString(params); | ||
var setCacheFn = createApiHooksConfig.setCacheFn; | ||
var getCacheFn = createApiHooksConfig.getCacheFn; | ||
var setCacheFn = { | ||
local: function (name, value) { return localStorage.setItem(name, value); }, | ||
session: function (name, value) { return sessionStorage.setItem(name, value); }, | ||
}[cache + ''] || createApiHooksConfig.setCacheFn; | ||
var getCacheFn = { | ||
local: function (name) { return localStorage.getItem(name); }, | ||
session: function (name) { return sessionStorage.getItem(name); }, | ||
}[cache + ''] || createApiHooksConfig.getCacheFn; | ||
if ((JSON.stringify(preParams.current) === JSON.stringify(params) && | ||
@@ -43,0 +49,0 @@ !isOutRequest) || |
{ | ||
"name": "create-api-hooks", | ||
"version": "0.0.40", | ||
"version": "0.0.41", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "author": "mushan0x0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40403
330