Skip to content

Commit

Permalink
Drop using of EmberArray in favour of native array
Browse files Browse the repository at this point in the history
in the main `collection`.

This is done in scope of removing depdencies on Ember
see san650#512
  • Loading branch information
ro0gr committed Nov 22, 2020
1 parent a2d9009 commit c71d552
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions addon-test-support/properties/collection/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* global Symbol */
import { A } from '@ember/array';
import { buildSelector, assign, isPageObject, getPageObjectDefinition } from '../../-private/helpers';
import { create } from '../../create';
import { count } from '../count';
Expand Down Expand Up @@ -53,8 +52,14 @@ export class Collection {
return this.toArray().filter(...args);
}

filterBy(...args) {
return this.toArray().filterBy(...args);
filterBy(propertyKey, value) {
return this.toArray().filter((i) => {
if (typeof value !== 'undefined') {
return i[propertyKey] === value;
} else {
return Boolean(i[propertyKey]);
}
});
}

forEach(...args) {
Expand All @@ -65,18 +70,20 @@ export class Collection {
return this.toArray().map(...args);
}

mapBy(...args) {
return this.toArray().mapBy(...args);
mapBy(propertyKey) {
return this.toArray().map((i) => {
return i[propertyKey];
});
}

findOneBy(...args) {
const elements = this.toArray().filterBy(...args);
const elements = this.filterBy(...args);
this._assertFoundElements(elements, ...args);
return elements[0];
}

findOne(...args) {
const elements = this.toArray().filter(...args);
const elements = this.filter(...args);
this._assertFoundElements(elements, ...args);
return elements[0];
}
Expand All @@ -99,7 +106,7 @@ export class Collection {
toArray() {
let { length } = this;

let array = A();
let array = [];

for (let i = 0; i < length; i++) {
array.push(this.objectAt(i));
Expand Down

0 comments on commit c71d552

Please sign in to comment.