Make Collection.find/exists error when using with IDs

This commit is contained in:
Schuyler Cebulskie
2016-11-13 00:27:56 -05:00
parent af5e07fb33
commit ee3a03f707

View File

@@ -138,6 +138,7 @@ class Collection extends Map {
find(propOrFn, value) { find(propOrFn, value) {
if (typeof propOrFn === 'string') { if (typeof propOrFn === 'string') {
if (typeof value === 'undefined') throw new Error('Value must be specified.'); if (typeof value === 'undefined') throw new Error('Value must be specified.');
if (propOrFn === 'id') throw new RangeError('Don\'t use .find() with IDs. Instead, use .get(id).');
for (const item of this.values()) { for (const item of this.values()) {
if (item[propOrFn] === value) return item; if (item[propOrFn] === value) return item;
} }
@@ -196,6 +197,7 @@ class Collection extends Map {
* } * }
*/ */
exists(prop, value) { exists(prop, value) {
if (prop === 'id') throw new RangeError('Don\'t use .find() with IDs. Instead, use .get(id).');
return Boolean(this.find(prop, value)); return Boolean(this.find(prop, value));
} }