diff --git a/lib/Util/Cache.js b/lib/Util/Cache.js index 9d71c0a7f..d3a0a6345 100644 --- a/lib/Util/Cache.js +++ b/lib/Util/Cache.js @@ -21,18 +21,17 @@ var Cache = (function (_Array) { } Cache.prototype.get = function get(key, value) { - if (key === this[discrimS] && typeof value === "string") { + if (typeof key === 'function') { + var valid = key; + key = null; + } else if (key === this[discrimS] && typeof value === "string") { return this[discrimCacheS][value] || null; - } - - var valid = value; - - if (value.constructor.name === 'RegExp') { - valid = function valid(item) { + } else if (value.constructor.name === 'RegExp') { + var valid = function valid(item) { return value.test(item); }; } else if (typeof value !== 'function') { - valid = function valid(item) { + var valid = function valid(item) { return item == value; }; } @@ -51,7 +50,7 @@ var Cache = (function (_Array) { var item = _ref; - if (valid(item[key])) { + if (valid(key == null ? item : item[key])) { return item; } } @@ -66,14 +65,15 @@ var Cache = (function (_Array) { Cache.prototype.getAll = function getAll(key, value) { var found = new Cache(this[discrimS]); - var valid = value; - - if (value.constructor.name === 'RegExp') { - valid = function valid(item) { + if (typeof key === 'function') { + var valid = key; + key = null; + } else if (value.constructor.name === 'RegExp') { + var valid = function valid(item) { return value.test(item); }; } else if (typeof value !== 'function') { - valid = function valid(item) { + var valid = function valid(item) { return item == value; }; } @@ -92,7 +92,7 @@ var Cache = (function (_Array) { var item = _ref2; - if (valid(item[key])) { + if (valid(key == null ? item : item[key])) { found.add(item); } } diff --git a/src/Util/Cache.js b/src/Util/Cache.js index 843520533..d5a86c8bf 100644 --- a/src/Util/Cache.js +++ b/src/Util/Cache.js @@ -11,24 +11,23 @@ export default class Cache extends Array { } get(key, value) { - if (key === this[discrimS] && typeof value === "string") { + if (typeof key === 'function') { + var valid = key; + key = null; + } else if (key === this[discrimS] && typeof value === "string") { return this[discrimCacheS][value] || null; - } - - var valid = value; - - if (value.constructor.name === 'RegExp') { - valid = function valid(item) { + } else if (value.constructor.name === 'RegExp') { + var valid = function valid(item) { return value.test(item); } } else if (typeof value !== 'function') { - valid = function valid(item) { + var valid = function valid(item) { return item == value; } } for (var item of this) { - if (valid(item[key])) { + if (valid(key == null ? item : item[key])) { return item; } } @@ -43,20 +42,21 @@ export default class Cache extends Array { getAll(key, value) { var found = new Cache(this[discrimS]); - var valid = value; - - if (value.constructor.name === 'RegExp') { - valid = function valid(item) { + if (typeof key === 'function') { + var valid = key; + key = null; + } else if (value.constructor.name === 'RegExp') { + var valid = function valid(item) { return value.test(item); } } else if (typeof value !== 'function') { - valid = function valid(item) { + var valid = function valid(item) { return item == value; } } for (var item of this) { - if (valid(item[key])) { + if (valid(key == null ? item : item[key])) { found.add(item); } }