1
1
import * as pathModule from 'path' ;
2
+ import { FanOutUnsubscribe } from 'thingies/lib/fanout' ;
2
3
import { Link , Superblock } from '../core' ;
3
4
import Stats from './Stats' ;
4
5
import Dirent from './Dirent' ;
@@ -2058,13 +2059,14 @@ export class FSWatcher extends EventEmitter {
2058
2059
}
2059
2060
}
2060
2061
// link children add/remove
2061
- link . on ( 'child:add' , onLinkChildAdd ) ;
2062
- link . on ( 'child:delete' , onLinkChildDelete ) ;
2062
+ const unsubscribeLinkChanges = link . changes . listen ( ( event ) => {
2063
+ if ( event . type === 'child:add' ) onLinkChildAdd ( event . link ) ;
2064
+ else if ( event . type === 'child:delete' ) onLinkChildDelete ( event . link ) ;
2065
+ } ) ;
2063
2066
2064
2067
const removers = this . _listenerRemovers . get ( node . ino ) ?? [ ] ;
2065
2068
removers . push ( ( ) => {
2066
- link . removeListener ( 'child:add' , onLinkChildAdd ) ;
2067
- link . removeListener ( 'child:delete' , onLinkChildDelete ) ;
2069
+ unsubscribeLinkChanges ( ) ;
2068
2070
} ) ;
2069
2071
2070
2072
if ( recursive ) {
@@ -2080,26 +2082,23 @@ export class FSWatcher extends EventEmitter {
2080
2082
2081
2083
const parent = this . _link . parent ;
2082
2084
if ( parent ) {
2083
- // parent.on('child:add', this._onParentChild);
2084
- parent . setMaxListeners ( parent . getMaxListeners ( ) + 1 ) ;
2085
- parent . on ( 'child:delete' , this . _onParentChild ) ;
2085
+ // parent.on('child:delete', this._onParentChild);
2086
+ parent . changes . listen ( ( event ) => {
2087
+ if ( event . type === 'child:delete' ) this . _onParentChild ( event . link ) ;
2088
+ } ) ;
2086
2089
}
2087
2090
2088
2091
if ( persistent ) this . _persist ( ) ;
2089
2092
}
2090
2093
2094
+ protected _parentChangesUnsub : FanOutUnsubscribe ;
2095
+
2091
2096
close ( ) {
2092
2097
clearTimeout ( this . _timer ) ;
2093
-
2094
2098
this . _listenerRemovers . forEach ( removers => {
2095
2099
removers . forEach ( r => r ( ) ) ;
2096
2100
} ) ;
2097
2101
this . _listenerRemovers . clear ( ) ;
2098
-
2099
- const parent = this . _link . parent ;
2100
- if ( parent ) {
2101
- // parent.removeListener('child:add', this._onParentChild);
2102
- parent . removeListener ( 'child:delete' , this . _onParentChild ) ;
2103
- }
2102
+ this . _parentChangesUnsub ?.( ) ;
2104
2103
}
2105
2104
}
0 commit comments