@shopify/decorators
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -10,2 +10,8 @@ # Changelog | ||
## 1.1.0 - 2019-03-22 | ||
### Changed | ||
- move to use the enhancer version of `memoize` ([#594](https://github.com/Shopify/quilt/pull/594)) | ||
## 1.0.1 - 2019-03-11 | ||
@@ -12,0 +18,0 @@ |
@@ -1,4 +0,2 @@ | ||
declare type Resolver<T extends Function> = T; | ||
export declare const MAX_MAP_ENTRIES = 50; | ||
export declare type Resolver<T extends Function> = T; | ||
export default function memoize<Method extends Function>(resolver?: Resolver<Method>): MethodDecorator; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
exports.MAX_MAP_ENTRIES = 50; | ||
var function_enhancers_1 = require("@shopify/function-enhancers"); | ||
function memoize(resolver) { | ||
@@ -15,3 +14,3 @@ return function (_target, propertyKey, descriptor) { | ||
configurable: true, | ||
value: memoized(method, resolver), | ||
value: function_enhancers_1.memoize(method, resolver), | ||
}; | ||
@@ -25,44 +24,1 @@ Object.defineProperty(this, propertyKey, newDescriptor); | ||
exports.default = memoize; | ||
function memoized(method, resolver) { | ||
var weakMapCache = new WeakMap(); | ||
var mapCache = new Map(); | ||
var mapKeys = []; | ||
return function memoized() { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
if (typeof window === 'undefined') { | ||
return method.apply(this, args); | ||
} | ||
var useWeakMap = args.length === 1 && typeof args[0] === 'object' && !resolver; | ||
var key; | ||
if (useWeakMap) { | ||
key = args[0]; | ||
} | ||
else if (resolver && resolver instanceof Function) { | ||
key = resolver.apply(void 0, tslib_1.__spread(args)); | ||
} | ||
else { | ||
key = args[0]; | ||
} | ||
var cache = useWeakMap ? weakMapCache : mapCache; | ||
if (cache.has(key)) { | ||
return cache.get(key); | ||
} | ||
var result = method.apply(this, args); | ||
if (useWeakMap) { | ||
weakMapCache.set(key, result); | ||
} | ||
else { | ||
mapCache.set(key, result); | ||
mapKeys.push(key); | ||
if (mapCache.size > exports.MAX_MAP_ENTRIES) { | ||
var oldestKey = mapKeys[0]; | ||
mapCache.delete(oldestKey); | ||
mapKeys.shift(); | ||
} | ||
} | ||
return result; | ||
}; | ||
} |
{ | ||
"name": "@shopify/decorators", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -31,3 +31,6 @@ "description": "A set of decorators to aid your JavaScript journey.", | ||
"dist/*" | ||
] | ||
], | ||
"dependencies": { | ||
"@shopify/function-enhancers": "^1.0.0" | ||
} | ||
} |
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
6137
1
29
+ Added@shopify/function-enhancers@1.1.5(transitive)