Skip to content

Commit

Permalink
Merge pull request #1841 from k-g-a/fix-array-dehance
Browse files Browse the repository at this point in the history
Fix array dehance (#1839)
  • Loading branch information
mweststrate authored Dec 11, 2018
2 parents ea30f7d + fe2acb1 commit daf6ac0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 5.7.1 / 4.7.1
* Fixed [#1839](https://github.com/mobxjs/mobx/issues/1839), ObservableArrayAdministration.dehanceValues does not dehance last value.

# 5.7.0 / 4.7.0

* Upgraded typings to TypeScript 3
Expand Down
2 changes: 1 addition & 1 deletion src/types/observablearray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class ObservableArrayAdministration
}

dehanceValues(values: any[]): any[] {
if (this.dehancer !== undefined && this.values.length > 0)
if (this.dehancer !== undefined && values.length > 0)
return values.map(this.dehancer) as any
return values
}
Expand Down
19 changes: 18 additions & 1 deletion test/base/array.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict"

var mobx = require("../../src/mobx.ts")
const { observable, $mobx, when } = mobx
const { observable, $mobx, when, _getAdministration } = mobx
var iterall = require("iterall")

function buffer() {
Expand Down Expand Up @@ -492,3 +493,19 @@ test("concats correctly #1667", () => {
expect(x.data[0]).toBe(first)
expect(x.data.length).toBe(11000)
})

test("dehances last value on shift/pop", () => {
const x1 = observable([3, 5])
_getAdministration(x1).dehancer = value => {
return value * 2
}
expect(x1.shift()).toBe(6)
expect(x1.shift()).toBe(10)

const x2 = observable([3, 5])
_getAdministration(x2).dehancer = value => {
return value * 2
}
expect(x2.pop()).toBe(10)
expect(x2.pop()).toBe(6)
})

0 comments on commit daf6ac0

Please sign in to comment.