Skip to content

Commit

Permalink
fix(Entity): Do not add Array.prototype properties to store (#782)
Browse files Browse the repository at this point in the history
Closes #781
  • Loading branch information
livthomas authored and MikeRyanDev committed Feb 9, 2018
1 parent ecf1ebf commit d537758
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 14 additions & 0 deletions modules/entity/spec/unsorted_state_adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ describe('Unsorted 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
5 changes: 2 additions & 3 deletions modules/entity/src/unsorted_state_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ export function createUnsortedStateAdapter<T>(selectId: IdSelector<T>): any {
function addManyMutably(entities: any[], state: any): DidMutate {
let didMutate = false;

for (let index in entities) {
didMutate =
addOneMutably(entities[index], state) !== DidMutate.None || didMutate;
for (const entity of entities) {
didMutate = addOneMutably(entity, state) !== DidMutate.None || didMutate;
}

return didMutate ? DidMutate.Both : DidMutate.None;
Expand Down

0 comments on commit d537758

Please sign in to comment.