Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix array dehance (#1839) #1841

Merged
merged 2 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})