Skip to content

Commit

Permalink
Fixed #1796, detect undelete of undefined property
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Nov 6, 2018
1 parent 4a274fa commit 3a6b072
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/types/dynamicobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ const objectProxyTraps: ProxyHandler<any> = {
return target[name]
const adm = getAdm(target)
const observable = adm.values.get(name as string)
if (observable instanceof Atom) return (observable as any).get()
if (observable instanceof Atom) {
const result = (observable as any).get()
if (result === undefined) {
// This fixes #1796, because deleting a prop that has an
// undefined value won't retrigger a observer (no visible effect),
// the autorun wouldn't subscribe to future key changes (see also next comment)
adm.has(name as any)
}
return result
}
// make sure we start listening to future keys
// note that we only do this here for optimization
if (typeof name === "string") adm.has(name)
Expand Down
19 changes: 19 additions & 0 deletions test/base/proxies.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,22 @@ test("predictable 'this' - 2", () => {
expect(a.a2()).toBe(a)
expect(a.computed).toBe(a)
})

test("1796 - deleting / recreate prop", () => {
let value = observable({
foo: undefined // if foo is something like 'abc', it works.
})

const events = []

const aut = autorun(() => {
events.push(value.foo)
})
delete value.foo
value.foo = "def"
expect(events).toEqual([
undefined,
undefined, // ideally not, but ok..
"def"
])
})

0 comments on commit 3a6b072

Please sign in to comment.