@ -232,7 +232,7 @@ describe('signals', () => {
// Ensure we're not leaking dependencies
assert . deepEqual (
nested . slice ( 0 , - 2 ) . map ( ( s ) = > s . deps ) ,
[ null , null ]
[ null , null , null , null ]
) ;
} ;
} ) ;
@ -446,4 +446,95 @@ describe('signals', () => {
assert . equal ( state ? . reactions , null ) ;
} ;
} ) ;
test ( 'deriveds update upon reconnection #1' , ( ) = > {
let a = source ( false ) ;
let b = source ( false ) ;
let c = derived ( ( ) = > $ . get ( a ) ) ;
let d = derived ( ( ) = > $ . get ( c ) ) ;
let last : Record < string , boolean | null > = { } ;
render_effect ( ( ) = > {
last = {
a : $.get ( a ) ,
b : $.get ( b ) ,
c : $.get ( c ) ,
d : $.get ( a ) || $ . get ( b ) ? $ . get ( d ) : null
} ;
} ) ;
return ( ) = > {
assert . deepEqual ( last , { a : false , b : false , c : false , d : null } ) ;
flushSync ( ( ) = > set ( a , true ) ) ;
flushSync ( ( ) = > set ( b , true ) ) ;
assert . deepEqual ( last , { a : true , b : true , c : true , d : true } ) ;
flushSync ( ( ) = > set ( a , false ) ) ;
flushSync ( ( ) = > set ( b , false ) ) ;
assert . deepEqual ( last , { a : false , b : false , c : false , d : null } ) ;
flushSync ( ( ) = > set ( a , true ) ) ;
flushSync ( ( ) = > set ( b , true ) ) ;
assert . deepEqual ( last , { a : true , b : true , c : true , d : true } ) ;
flushSync ( ( ) = > set ( a , false ) ) ;
flushSync ( ( ) = > set ( b , false ) ) ;
assert . deepEqual ( last , { a : false , b : false , c : false , d : null } ) ;
flushSync ( ( ) = > set ( b , true ) ) ;
assert . deepEqual ( last , { a : false , b : true , c : false , d : false } ) ;
} ;
} ) ;
test ( 'deriveds update upon reconnection #2' , ( ) = > {
let a = source ( false ) ;
let b = source ( false ) ;
let c = source ( false ) ;
let d = derived ( ( ) = > $ . get ( a ) || $ . get ( b ) ) ;
let branch = '' ;
render_effect ( ( ) = > {
if ( $ . get ( c ) && ! $ . get ( d ) ) {
branch = 'if' ;
} else {
branch = 'else' ;
}
} ) ;
return ( ) = > {
assert . deepEqual ( branch , 'else' ) ;
flushSync ( ( ) = > set ( c , true ) ) ;
assert . deepEqual ( branch , 'if' ) ;
flushSync ( ( ) = > set ( a , true ) ) ;
assert . deepEqual ( branch , 'else' ) ;
set ( a , false ) ;
set ( b , false ) ;
set ( c , false ) ;
flushSync ( ) ;
assert . deepEqual ( branch , 'else' ) ;
flushSync ( ( ) = > set ( c , true ) ) ;
assert . deepEqual ( branch , 'if' ) ;
flushSync ( ( ) = > set ( b , true ) ) ;
assert . deepEqual ( branch , 'else' ) ;
set ( a , false ) ;
set ( b , false ) ;
set ( c , false ) ;
flushSync ( ) ;
assert . deepEqual ( branch , 'else' ) ;
flushSync ( ( ) = > set ( c , true ) ) ;
assert . deepEqual ( branch , 'if' ) ;
} ;
} ) ;
} ) ;