Skip to content

Commit dd09a2f

Browse files
committed
fix + test
1 parent d55c50a commit dd09a2f

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎src/types/observablearray.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class ObservableArrayAdministration
154154
}
155155

156156
dehanceValues(values: any[]): any[] {
157-
if (this.dehancer !== undefined && this.values.length > 0)
157+
if (this.dehancer !== undefined && values.length > 0)
158158
return values.map(this.dehancer) as any
159159
return values
160160
}

‎test/base/array.js‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict"
2+
23
var mobx = require("../../src/mobx.ts")
3-
const { observable, $mobx, when } = mobx
4+
const { observable, $mobx, when, _getAdministration } = mobx
45
var iterall = require("iterall")
56

67
function buffer() {
@@ -492,3 +493,19 @@ test("concats correctly #1667", () => {
492493
expect(x.data[0]).toBe(first)
493494
expect(x.data.length).toBe(11000)
494495
})
496+
497+
test("dehances last value on shift/pop", () => {
498+
const x1 = observable([3, 5])
499+
_getAdministration(x1).dehancer = value => {
500+
return value * 2
501+
}
502+
expect(x1.shift()).toBe(6)
503+
expect(x1.shift()).toBe(10)
504+
505+
const x2 = observable([3, 5])
506+
_getAdministration(x2).dehancer = value => {
507+
return value * 2
508+
}
509+
expect(x2.pop()).toBe(10)
510+
expect(x2.pop()).toBe(6)
511+
})

0 commit comments

Comments
 (0)