Allow get/getAll to take a function only

This commit is contained in:
abalabahaha
2016-01-31 22:37:31 -08:00
parent 580f260933
commit 6f7bd987b8
2 changed files with 30 additions and 30 deletions

View File

@@ -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);
}
}

View File

@@ -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);
}
}