Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/observe-value-change-kind.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mobx": patch
---

Include `observableKind` and `debugObjectName` in the change events that `observe` reports for boxed observables, observable object properties and observable map entries, as the `IValueDidChange` type and the docs describe.
17 changes: 17 additions & 0 deletions packages/mobx/__tests__/base/observe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,20 @@ test("observe disposer can be called from within a listener", () => {
o.x = 2
expect(calls).toEqual(["a", "b", "b"])
})

test("observe value changes report observableKind and debugObjectName", () => {
const box = observable.box(1, { name: "box" })
const o = observable({ a: 1 }, {}, { name: "o" })
const events: any[] = []
observe(box, e => events.push(e), true)
observe(o, "a", e => events.push(e))

box.set(2)
o.a = 2

expect(events.map(e => [e.observableKind, e.debugObjectName, e.newValue])).toEqual([
["value", "box", 1],
["value", "box", 2],
["value", "o.a", 2]
])
})
2 changes: 2 additions & 0 deletions packages/mobx/src/types/observablevalue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export class ObservableValue<T>
this.reportChanged()
if (hasListeners(this)) {
notifyListeners(this, {
observableKind: "value",
debugObjectName: this.name_,
type: UPDATE,
object: this,
newValue,
Expand Down