Skip to content

Commit

Permalink
fix(Entity): Avoid for..in iteration in sorted state adapter (#805)
Browse files Browse the repository at this point in the history
  • Loading branch information
livthomas authored and MikeRyanDev committed Feb 11, 2018
1 parent 779d689 commit 4192645
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 14 additions & 0 deletions modules/entity/spec/sorted_state_adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ describe('Sorted State Adapter', () => {
let adapter: EntityStateAdapter<BookModel>;
let state: EntityState<BookModel>;

beforeAll(() => {
Object.defineProperty(Array.prototype, 'unwantedField', {
enumerable: true,
configurable: true,
value: 'This should not appear anywhere',
});
});

afterAll(() => {
Object.defineProperty(Array.prototype, 'unwantedField', {
value: undefined,
});
});

beforeEach(() => {
adapter = createEntityAdapter({
selectId: (book: BookModel) => book.id,
Expand Down
3 changes: 1 addition & 2 deletions modules/entity/src/sorted_state_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ export function createSortedStateAdapter<T>(selectId: any, sort: any): any {
const added: T[] = [];
const updated: Update<T>[] = [];

for (let index in updates) {
const update = updates[index];
for (const update of updates) {
if (update.id in state.entities) {
updated.push(update);
} else {
Expand Down

0 comments on commit 4192645

Please sign in to comment.