@thi.ng/memoize
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -6,2 +6,10 @@ # Change Log | ||
## [1.0.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/memoize@1.0.2...@thi.ng/memoize@1.0.3) (2019-03-01) | ||
**Note:** Version bump only for package @thi.ng/memoize | ||
## [1.0.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/memoize@1.0.1...@thi.ng/memoize@1.0.2) (2019-02-05) | ||
@@ -8,0 +16,0 @@ |
@@ -16,4 +16,2 @@ const cache = {}; | ||
*/ | ||
export const defonce = (id, factory) => cache.hasOwnProperty(id) ? | ||
cache[id] : | ||
(cache[id] = factory()); | ||
export const defonce = (id, factory) => cache.hasOwnProperty(id) ? cache[id] : (cache[id] = factory()); |
@@ -6,5 +6,3 @@ 'use strict'; | ||
const cache = {}; | ||
const defonce = (id, factory) => cache.hasOwnProperty(id) ? | ||
cache[id] : | ||
(cache[id] = factory()); | ||
const defonce = (id, factory) => cache.hasOwnProperty(id) ? cache[id] : (cache[id] = factory()); | ||
@@ -14,5 +12,5 @@ function memoize(fn, cache) { | ||
let res; | ||
return cache.has(args) ? | ||
cache.get(args) : | ||
(cache.set(args, res = fn.apply(null, args)), res); | ||
return cache.has(args) | ||
? cache.get(args) | ||
: (cache.set(args, (res = fn.apply(null, args))), res); | ||
}; | ||
@@ -25,5 +23,3 @@ } | ||
let res; | ||
return cache.has(x) ? | ||
cache.get(x) : | ||
(cache.set(x, res = fn(x)), res); | ||
return cache.has(x) ? cache.get(x) : (cache.set(x, (res = fn(x))), res); | ||
}; | ||
@@ -37,5 +33,5 @@ } | ||
if (key !== undefined) { | ||
return key in cache ? | ||
cache[key] : | ||
(cache[key] = fn.apply(null, args)); | ||
return key in cache | ||
? cache[key] | ||
: (cache[key] = fn.apply(null, args)); | ||
} | ||
@@ -42,0 +38,0 @@ return fn.apply(null, args); |
@@ -8,5 +8,3 @@ (function (global, factory) { | ||
const cache = {}; | ||
const defonce = (id, factory) => cache.hasOwnProperty(id) ? | ||
cache[id] : | ||
(cache[id] = factory()); | ||
const defonce = (id, factory) => cache.hasOwnProperty(id) ? cache[id] : (cache[id] = factory()); | ||
@@ -16,5 +14,5 @@ function memoize(fn, cache) { | ||
let res; | ||
return cache.has(args) ? | ||
cache.get(args) : | ||
(cache.set(args, res = fn.apply(null, args)), res); | ||
return cache.has(args) | ||
? cache.get(args) | ||
: (cache.set(args, (res = fn.apply(null, args))), res); | ||
}; | ||
@@ -27,5 +25,3 @@ } | ||
let res; | ||
return cache.has(x) ? | ||
cache.get(x) : | ||
(cache.set(x, res = fn(x)), res); | ||
return cache.has(x) ? cache.get(x) : (cache.set(x, (res = fn(x))), res); | ||
}; | ||
@@ -39,5 +35,5 @@ } | ||
if (key !== undefined) { | ||
return key in cache ? | ||
cache[key] : | ||
(cache[key] = fn.apply(null, args)); | ||
return key in cache | ||
? cache[key] | ||
: (cache[key] = fn.apply(null, args)); | ||
} | ||
@@ -44,0 +40,0 @@ return fn.apply(null, args); |
export function memoize(fn, cache) { | ||
return (...args) => { | ||
let res; | ||
return cache.has(args) ? | ||
cache.get(args) : | ||
(cache.set(args, res = fn.apply(null, args)), res); | ||
return cache.has(args) | ||
? cache.get(args) | ||
: (cache.set(args, (res = fn.apply(null, args))), res); | ||
}; | ||
} |
@@ -16,6 +16,4 @@ /** | ||
let res; | ||
return cache.has(x) ? | ||
cache.get(x) : | ||
(cache.set(x, res = fn(x)), res); | ||
return cache.has(x) ? cache.get(x) : (cache.set(x, (res = fn(x))), res); | ||
}; | ||
} |
@@ -6,5 +6,5 @@ export function memoizeJ(fn, cache) { | ||
if (key !== undefined) { | ||
return key in cache ? | ||
cache[key] : | ||
(cache[key] = fn.apply(null, args)); | ||
return key in cache | ||
? cache[key] | ||
: (cache[key] = fn.apply(null, args)); | ||
} | ||
@@ -11,0 +11,0 @@ return fn.apply(null, args); |
{ | ||
"name": "@thi.ng/memoize", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Function memoization with configurable caches", | ||
@@ -35,3 +35,3 @@ "module": "./index.js", | ||
"dependencies": { | ||
"@thi.ng/api": "^5.0.2" | ||
"@thi.ng/api": "^5.0.3" | ||
}, | ||
@@ -49,3 +49,3 @@ "keywords": [ | ||
"sideEffects": false, | ||
"gitHead": "74fb4d83013785ce7a95357c565426a046657e74" | ||
"gitHead": "e43f57c7554fd78380bba58d37ae62ca01221eeb" | ||
} |
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
28743
215
Updated@thi.ng/api@^5.0.3