Skip to content

Commit 4ccf47c

Browse files
committed
Update object api set to write through parent mobx administrator
1 parent dbe4c93 commit 4ccf47c

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/api/object-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function set(obj: any, key: any, value?: any): void {
6565
const adm = ((obj as any) as IIsObservableObject).$mobx
6666
const existingObservable = adm.values[key]
6767
if (existingObservable) {
68-
existingObservable.set(value)
68+
adm.write(obj, key, value)
6969
} else {
7070
defineObservableProperty(obj, key, value, adm.defaultEnhancer)
7171
}

test/base/object-api.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,25 @@ test("observe & intercept", () => {
177177
})
178178
})
179179

180+
test("observe & intercept set called multiple times", () => {
181+
const a = mobx.observable({})
182+
const interceptLogs = []
183+
const observeLogs = []
184+
185+
mobx.intercept(a, change => {
186+
interceptLogs.push(`${change.name}: ${change.newValue}`)
187+
return change
188+
})
189+
mobx.observe(a, change => observeLogs.push(`${change.name}: ${change.newValue}`))
190+
191+
mobx.set(a, "x", 0)
192+
a.x = 1
193+
mobx.set(a, "x", 2)
194+
195+
expect(interceptLogs).toEqual(["x: 0", "x: 1", "x: 2"])
196+
expect(observeLogs).toEqual(["x: 0", "x: 1", "x: 2"])
197+
})
198+
180199
test("dynamically adding properties should preserve the original modifiers of an object", () => {
181200
const todos = observable(
182201
{

0 commit comments

Comments
 (0)