@@ -655,21 +655,21 @@ function endEffect(this: Effect, prevContext?: Computed | Effect) {
655
655
}
656
656
657
657
declare class Effect {
658
- _compute ?: ( ) => unknown ;
659
- _cleanup ?: unknown ;
658
+ _compute ?: ( ) => void | ( ( ) => void ) ;
659
+ _cleanup ?: ( ) => void ;
660
660
_sources ?: Node ;
661
661
_nextBatchedEffect ?: Effect ;
662
662
_flags : number ;
663
663
664
- constructor ( compute : ( ) => void ) ;
664
+ constructor ( compute : ( ) => void | ( ( ) => void ) ) ;
665
665
666
666
_callback ( ) : void ;
667
667
_start ( ) : ( ) => void ;
668
668
_notify ( ) : void ;
669
669
_dispose ( ) : void ;
670
670
}
671
671
672
- function Effect ( this : Effect , compute : ( ) => void ) {
672
+ function Effect ( this : Effect , compute : ( ) => void | ( ( ) => void ) ) {
673
673
this . _compute = compute ;
674
674
this . _cleanup = undefined ;
675
675
this . _sources = undefined ;
@@ -680,8 +680,12 @@ function Effect(this: Effect, compute: () => void) {
680
680
Effect . prototype . _callback = function ( ) {
681
681
const finish = this . _start ( ) ;
682
682
try {
683
- if ( ! ( this . _flags & DISPOSED ) && this . _compute !== undefined ) {
684
- this . _cleanup = this . _compute ( ) ;
683
+ if ( this . _flags & DISPOSED ) return ;
684
+ if ( this . _compute === undefined ) return ;
685
+
686
+ const cleanup = this . _compute ( ) ;
687
+ if ( typeof cleanup === "function" ) {
688
+ this . _cleanup = cleanup ;
685
689
}
686
690
} finally {
687
691
finish ( ) ;
@@ -719,7 +723,7 @@ Effect.prototype._dispose = function () {
719
723
}
720
724
} ;
721
725
722
- function effect ( compute : ( ) => unknown ) : ( ) => void {
726
+ function effect ( compute : ( ) => void | ( ( ) => void ) ) : ( ) => void {
723
727
const effect = new Effect ( compute ) ;
724
728
try {
725
729
effect . _callback ( ) ;
0 commit comments