Skip to content

Commit d537758

Browse files
livthomasMikeRyanDev
authored andcommitted
fix(Entity): Do not add Array.prototype properties to store (#782)
Closes #781
1 parent ecf1ebf commit d537758

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

modules/entity/spec/unsorted_state_adapter.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ describe('Unsorted State Adapter', () => {
1111
let adapter: EntityStateAdapter<BookModel>;
1212
let state: EntityState<BookModel>;
1313

14+
beforeAll(() => {
15+
Object.defineProperty(Array.prototype, 'unwantedField', {
16+
enumerable: true,
17+
configurable: true,
18+
value: 'This should not appear anywhere',
19+
});
20+
});
21+
22+
afterAll(() => {
23+
Object.defineProperty(Array.prototype, 'unwantedField', {
24+
value: undefined,
25+
});
26+
});
27+
1428
beforeEach(() => {
1529
adapter = createEntityAdapter({
1630
selectId: (book: BookModel) => book.id,

modules/entity/src/unsorted_state_adapter.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ export function createUnsortedStateAdapter<T>(selectId: IdSelector<T>): any {
2525
function addManyMutably(entities: any[], state: any): DidMutate {
2626
let didMutate = false;
2727

28-
for (let index in entities) {
29-
didMutate =
30-
addOneMutably(entities[index], state) !== DidMutate.None || didMutate;
28+
for (const entity of entities) {
29+
didMutate = addOneMutably(entity, state) !== DidMutate.None || didMutate;
3130
}
3231

3332
return didMutate ? DidMutate.Both : DidMutate.None;

0 commit comments

Comments
 (0)