8000 Do not keep a singletin of EMPTY_LIST · immutable-js/immutable-js@14631a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 14631a6

Browse files
committed
Do not keep a singletin of EMPTY_LIST
1 parent 8997771 commit 14631a6

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

__tests__/List.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ describe('List', () => {
829829
it('chained mutations does not result in new empty list instance', () => {
830830
const v1 = List(['x']);
831831
const v2 = v1.withMutations(v => v.push('y').pop().pop());
832-
expect(v2).toBe(List());
832+
expect(v2).toEqual(List());
833833
});
834834

835835
it('calling `clear` and `setSize` should set all items to undefined', () => {
@@ -952,11 +952,7 @@ describe('List', () => {
952952
});
953953

954954
it('Mutating empty list with a JS API should not mutate new instances', () => {
955-
expect(() => {
956-
Object.assign(List(), List([1, 2]));
957-
}).toThrow(
958-
"Cannot assign to read only property 'size' of object '[object Object]'"
959-
);
955+
Object.assign(List(), List([1, 2]));
960956

961957
expect(List().size).toBe(0);
962958
expect(List().toArray()).toEqual([]);

src/List.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,8 @@ function makeList(origin, capacity, level, root, tail, ownerID, hash) {
408408
return list;
409409
}
410410

411-
let EMPTY_LIST;
412411
export function emptyList() {
413-
if (!EMPTY_LIST) {
414-
EMPTY_LIST = makeL 6051 ist(0, 0, SHIFT);
415-
Object.freeze(EMPTY_LIST);
416-
}
417-
return EMPTY_LIST;
412+
return makeList(0, 0, SHIFT);
418413
}
419414

420415
function updateList(list, index, value) {

0 commit comments

Comments
 (0)
0