Skip to content

Commit

Permalink
Merge pull request #1840 from k-g-a/mobx4-fix-array-dehance
Browse files Browse the repository at this point in the history
Fix array dehance (#1839) for mobx4
  • Loading branch information
mweststrate authored Dec 11, 2018
2 parents 7d72d02 + f9922b0 commit 2547578
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/types/observablearray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class ObservableArrayAdministration<T>
}

dehanceValues(values: T[]): T[] {
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
17 changes: 17 additions & 0 deletions 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")
var observable = mobx.observable
var _getAdministration = mobx._getAdministration
var iterall = require("iterall")

function buffer() {
Expand Down Expand Up @@ -528,3 +529,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 2547578

Please sign in to comment.