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

Update object api set to write through parent mobx administrator #1514

Merged
merged 1 commit into from
Apr 26, 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
2 changes: 1 addition & 1 deletion src/api/object-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function set(obj: any, key: any, value?: any): void {
const adm = ((obj as any) as IIsObservableObject).$mobx
const existingObservable = adm.values[key]
if (existingObservable) {
existingObservable.set(value)
adm.write(obj, key, value)
} else {
defineObservableProperty(obj, key, value, adm.defaultEnhancer)
}
Expand Down
19 changes: 19 additions & 0 deletions test/base/object-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,25 @@ test("observe & intercept", () => {
})
})

test("observe & intercept set called multiple times", () => {
const a = mobx.observable({})
const interceptLogs = []
const observeLogs = []

mobx.intercept(a, change => {
interceptLogs.push(`${change.name}: ${change.newValue}`)
return change
})
mobx.observe(a, change => observeLogs.push(`${change.name}: ${change.newValue}`))

mobx.set(a, "x", 0)
a.x = 1
mobx.set(a, "x", 2)

expect(interceptLogs).toEqual(["x: 0", "x: 1", "x: 2"])
expect(observeLogs).toEqual(["x: 0", "x: 1", "x: 2"])
})

test("dynamically adding properties should preserve the original modifiers of an object", () => {
const todos = observable(
{
Expand Down