@wltech/libs
Advanced tools
Comparing version 0.0.0-dev.3 to 0.0.0-dev.4
@@ -56,2 +56,5 @@ 'use strict'; | ||
} | ||
if (typeof obj.clone === 'function') { | ||
return obj.clone(); | ||
} | ||
if (Array.isArray(obj)) { | ||
@@ -123,4 +126,8 @@ var newArray = []; | ||
return func.apply(void 0, args).then(function (res) { | ||
cache[apiKey] = res; | ||
return res; | ||
if (res.clone && typeof res.clone === 'function') { | ||
cache[apiKey] = res.clone(); | ||
} else { | ||
cache[apiKey] = res; | ||
} | ||
return cache[apiKey]; | ||
})["catch"](function (error) { | ||
@@ -127,0 +134,0 @@ throw error; |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return"object"!=typeof e&&"function"!=typeof e||null===e}function t(t){return e(t)?t:JSON.stringify(t,(function(e,t){return"object"!=typeof t||null===t||Array.isArray(t)?t:Object.keys(t).sort().reduce((function(e,n){return e[n]=t[n],e}),{})}))}function n(e){if(null===e||"object"!=typeof e)return e;if(Array.isArray(e)){for(var t=[],r=0;r<e.length;r++)t[r]=n(e[r]);return t}if("object"==typeof e){var o={};for(var i in e)e.hasOwnProperty(i)&&(o[i]=n(e[i]));return o}return e}Object.defineProperty(exports,"__esModule",{value:!0});var r={},o={timeout:6e4,timeoutResult:{code:408,msg:"请求超时"}};exports.cloneDeep=n,exports.generateDeterministicUniqueKey=t,exports.getGlobal=function(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:this},exports.isPrimitive=e,exports.wrapFunctionWithCache=function(e,i){return void 0===i&&(i=o),function(){for(var u=arguments.length,f=new Array(u),a=0;a<u;a++)f[a]=arguments[a];var l=t(f);if(r[l])return Promise.resolve(n(r[l]));var c=l+"_wl_loading";if(r[c]){var s=Object.assign({},o,i);return new Promise((function(e){var t=Date.now(),o=setInterval((function(){r[l]?(clearInterval(o),e(n(r[l]))):Date.now()-t>s.timeout&&(clearInterval(o),e(n(s.timeoutResult)))}),100)}))}return r[c]=!0,e.apply(void 0,f).then((function(e){return r[l]=e,e})).catch((function(e){throw e})).finally((function(){r[c]=!1}))}}; | ||
"use strict";function e(e){return"object"!=typeof e&&"function"!=typeof e||null===e}function t(t){return e(t)?t:JSON.stringify(t,(function(e,t){return"object"!=typeof t||null===t||Array.isArray(t)?t:Object.keys(t).sort().reduce((function(e,n){return e[n]=t[n],e}),{})}))}function n(e){if(null===e||"object"!=typeof e)return e;if("function"==typeof e.clone)return e.clone();if(Array.isArray(e)){for(var t=[],r=0;r<e.length;r++)t[r]=n(e[r]);return t}if("object"==typeof e){var o={};for(var i in e)e.hasOwnProperty(i)&&(o[i]=n(e[i]));return o}return e}Object.defineProperty(exports,"__esModule",{value:!0});var r={},o={timeout:6e4,timeoutResult:{code:408,msg:"请求超时"}};exports.cloneDeep=n,exports.generateDeterministicUniqueKey=t,exports.getGlobal=function(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:this},exports.isPrimitive=e,exports.wrapFunctionWithCache=function(e,i){return void 0===i&&(i=o),function(){for(var u=arguments.length,f=new Array(u),l=0;l<u;l++)f[l]=arguments[l];var c=t(f);if(r[c])return Promise.resolve(n(r[c]));var a=c+"_wl_loading";if(r[a]){var s=Object.assign({},o,i);return new Promise((function(e){var t=Date.now(),o=setInterval((function(){r[c]?(clearInterval(o),e(n(r[c]))):Date.now()-t>s.timeout&&(clearInterval(o),e(n(s.timeoutResult)))}),100)}))}return r[a]=!0,e.apply(void 0,f).then((function(e){return r[c]=e.clone&&"function"==typeof e.clone?e.clone():e,r[c]})).catch((function(e){throw e})).finally((function(){r[a]=!1}))}}; | ||
//# sourceMappingURL=libs.cjs.production.min.js.map |
@@ -52,2 +52,5 @@ // 获取全局对象 | ||
} | ||
if (typeof obj.clone === 'function') { | ||
return obj.clone(); | ||
} | ||
if (Array.isArray(obj)) { | ||
@@ -119,4 +122,8 @@ var newArray = []; | ||
return func.apply(void 0, args).then(function (res) { | ||
cache[apiKey] = res; | ||
return res; | ||
if (res.clone && typeof res.clone === 'function') { | ||
cache[apiKey] = res.clone(); | ||
} else { | ||
cache[apiKey] = res; | ||
} | ||
return cache[apiKey]; | ||
})["catch"](function (error) { | ||
@@ -123,0 +130,0 @@ throw error; |
@@ -8,3 +8,3 @@ interface Setting { | ||
*/ | ||
export declare function wrapFunctionWithCache<T>(func: (...args: any[]) => Promise<T>, setting?: Setting): (...args: any[]) => Promise<any>; | ||
export declare function wrapFunctionWithCache<T>(func: (...args: any[]) => Promise<T>, setting?: Setting): (...args: any[]) => Promise<T>; | ||
export {}; |
{ | ||
"name": "@wltech/libs", | ||
"author": "zhyswan", | ||
"version": "0.0.0-dev.3", | ||
"version": "0.0.0-dev.4", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "main": "dist/index.js", |
@@ -6,2 +6,6 @@ export function cloneDeep<T>(obj: T): T { | ||
if (typeof (obj as any).clone === 'function') { | ||
return (obj as any).clone(); | ||
} | ||
if (Array.isArray(obj)) { | ||
@@ -12,3 +16,3 @@ const newArray: any[] = []; | ||
} | ||
return newArray as unknown as T; | ||
return (newArray as unknown) as T; | ||
} | ||
@@ -15,0 +19,0 @@ |
@@ -29,3 +29,3 @@ // import { getGlobal } from './getGlobal'; | ||
) { | ||
return function(...args: any[]) { | ||
return function(...args: any[]): Promise<T> { | ||
const apiKey: string = generateDeterministicUniqueKey(args); //缓存key | ||
@@ -57,5 +57,9 @@ | ||
return func(...args) | ||
.then((res: any) => { | ||
cache[apiKey] = res; | ||
return res; | ||
.then(res => { | ||
if ((res as any).clone && typeof (res as any).clone === 'function') { | ||
cache[apiKey] = (res as any).clone(); | ||
} else { | ||
cache[apiKey] = res; | ||
} | ||
return cache[apiKey] as T; | ||
}) | ||
@@ -62,0 +66,0 @@ .catch((error: any) => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
41953
451