From ee3a03f7074ff2fe94dc7a74f46596d3b08d4ce5 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Sun, 13 Nov 2016 00:27:56 -0500 Subject: [PATCH] Make Collection.find/exists error when using with IDs --- src/util/Collection.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/Collection.js b/src/util/Collection.js index cd1226d21..42c272a37 100644 --- a/src/util/Collection.js +++ b/src/util/Collection.js @@ -138,6 +138,7 @@ class Collection extends Map { find(propOrFn, value) { if (typeof propOrFn === 'string') { 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()) { if (item[propOrFn] === value) return item; } @@ -196,6 +197,7 @@ class Collection extends Map { * } */ 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)); }