diff --git a/packages/ember-runtime/lib/computed/reduce_computed_macros.js b/packages/ember-runtime/lib/computed/reduce_computed_macros.js index 671c5a792b0..01cfe9e52d4 100644 --- a/packages/ember-runtime/lib/computed/reduce_computed_macros.js +++ b/packages/ember-runtime/lib/computed/reduce_computed_macros.js @@ -1,8 +1,6 @@ /** @module @ember/object */ - -import { guidFor } from 'ember-utils'; import { assert } from 'ember-debug'; import { get, @@ -407,12 +405,14 @@ export function filterBy(dependentKey, propertyKey, value) { export function uniq(...args) { return multiArrayMacro(args, function(dependentKeys) { let uniq = emberA(); + let seen = new Set(); dependentKeys.forEach(dependentKey => { let value = get(this, dependentKey); if (isArray(value)) { value.forEach(item => { - if (uniq.indexOf(item) === -1) { + if (!seen.has(item)) { + seen.add(item); uniq.push(item); } }); @@ -461,13 +461,13 @@ export function uniqBy(dependentKey, propertyKey) { let cp = new ComputedProperty(function() { let uniq = emberA(); - let seen = Object.create(null); let list = get(this, dependentKey); if (isArray(list)) { + let seen = new Set(); list.forEach(item => { - let guid = guidFor(get(item, propertyKey)); - if (!(guid in seen)) { - seen[guid] = true; + let val = get(item, propertyKey); + if (!seen.has(val)) { + seen.add(val); uniq.push(item); } }); diff --git a/packages/ember-runtime/lib/mixins/enumerable.js b/packages/ember-runtime/lib/mixins/enumerable.js index e4fa617abb6..b1845235abb 100644 --- a/packages/ember-runtime/lib/mixins/enumerable.js +++ b/packages/ember-runtime/lib/mixins/enumerable.js @@ -7,7 +7,6 @@ // HELPERS // -import { guidFor } from 'ember-utils'; import { get, set, @@ -811,9 +810,11 @@ const Enumerable = Mixin.create({ uniq() { let ret = emberA(); - this.forEach(k => { - if (ret.indexOf(k) < 0) { - ret.push(k); + let seen = new Set(); + this.forEach(item => { + if (!seen.has(item)) { + seen.add(item); + ret.push(item); } }); @@ -1066,12 +1067,12 @@ const Enumerable = Mixin.create({ uniqBy(key) { let ret = emberA(); - let seen = Object.create(null); + let seen = new Set(); this.forEach((item) => { - let guid = guidFor(get(item, key)); - if (!(guid in seen)) { - seen[guid] = true; + let val = get(item, key); + if (!seen.has(val)) { + seen.add(val); ret.push(item); } });