diff --git a/CHANGELOG.md b/CHANGELOG.md index 120ab0c33..5c5bce04c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/types/observablearray.ts b/src/types/observablearray.ts index abd120b4e..e04835f88 100644 --- a/src/types/observablearray.ts +++ b/src/types/observablearray.ts @@ -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 } diff --git a/test/base/array.js b/test/base/array.js index fa49e8292..ceaee689a 100644 --- a/test/base/array.js +++ b/test/base/array.js @@ -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() { @@ -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) +})