Skip to content

Commit

Permalink
Fixed array concatenation for large files, fixes #1667
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Aug 25, 2018
1 parent 8b8d3df commit 6fc2bf6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 5.0.5

* Fixed [#1667](https://github.com/mobxjs/mobx/issues/1667): creating a large array could result in undefined items (MobX 4.* was not affected)

# 4.3.2 / 5.0.4

* Fixed [#1685](https://github.com/mobxjs/mobx/issues/1685): expose `IAutorunOptions`
Expand Down
1 change: 1 addition & 0 deletions src/types/observablearray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ const arrayExtensions = {
* faster as everything works on unproxied values
*/
;[
"concat",
"every",
"filter",
"forEach",
Expand Down
19 changes: 19 additions & 0 deletions test/base/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,22 @@ test("can define properties on arrays", () => {
expect(ar.toString()).toBe("hoi")
expect("" + ar).toBe("hoi")
})

test("concats correctly #1667", () => {
const x = observable({ data: [] })

function generate(count) {
const d = []
for (let i = 0; i < count; i++) d.push({})
return d
}

x.data = generate(10000)
const first = x.data[0]
expect(Array.isArray(x.data)).toBe(true)

x.data = x.data.concat(generate(1000))
expect(Array.isArray(x.data)).toBe(true)
expect(x.data[0]).toBe(first)
expect(x.data.length).toBe(11000)
})

0 comments on commit 6fc2bf6

Please sign in to comment.