File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,7 +30,16 @@ const objectProxyTraps: ProxyHandler<any> = {
3030 return target [ name ]
3131 const adm = getAdm ( target )
3232 const observable = adm . values . get ( name as string )
33- if ( observable instanceof Atom ) return ( observable as any ) . get ( )
33+ if ( observable instanceof Atom ) {
34+ const result = ( observable as any ) . get ( )
35+ if ( result === undefined ) {
36+ // This fixes #1796, because deleting a prop that has an
37+ // undefined value won't retrigger a observer (no visible effect),
38+ // the autorun wouldn't subscribe to future key changes (see also next comment)
39+ adm . has ( name as any )
40+ }
41+ return result
42+ }
3443 // make sure we start listening to future keys
3544 // note that we only do this here for optimization
3645 if ( typeof name === "string" ) adm . has ( name )
Original file line number Diff line number Diff line change @@ -371,3 +371,22 @@ test("predictable 'this' - 2", () => {
371371 expect ( a . a2 ( ) ) . toBe ( a )
372372 expect ( a . computed ) . toBe ( a )
373373} )
374+
375+ test ( "1796 - deleting / recreate prop" , ( ) => {
376+ let value = observable ( {
377+ foo : undefined // if foo is something like 'abc', it works.
378+ } )
379+
380+ const events = [ ]
381+
382+ const aut = autorun ( ( ) => {
383+ events . push ( value . foo )
384+ } )
385+ delete value . foo
386+ value . foo = "def"
387+ expect ( events ) . toEqual ( [
388+ undefined ,
389+ undefined , // ideally not, but ok..
390+ "def"
391+ ] )
392+ } )
You can’t perform that action at this time.
0 commit comments