@@ -2,7 +2,9 @@ export class States <State extends string> implements Iterable<[id: string, stat
2
2
readonly byState : Partial < { [ state in State ] : Set < string > } > = { }
3
3
4
4
set ( id : string , state : State ) : void {
5
- this . clear ( id , state )
5
+ if ( ! this . clear ( id , state ) ) {
6
+ return
7
+ }
6
8
const bucket = this . byState [ state ]
7
9
if ( bucket === undefined ) {
8
10
this . byState [ state ] = new Set ( [ id ] )
@@ -26,19 +28,20 @@ export class States <State extends string> implements Iterable<[id: string, stat
26
28
}
27
29
}
28
30
29
- private clear ( id : string , unlessState ?: State ) : void {
31
+ private clear ( id : string , unlessState ?: State ) : boolean {
30
32
for ( const bucketState in this . byState ) {
31
- if ( bucketState === unlessState ) return
32
- const bucket = this . byState [ bucketState ]
33
- if ( bucket !== undefined ) {
34
- bucket . delete ( id )
35
- if ( bucket . size === 0 ) {
36
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
37
- delete this . byState [ bucketState ]
38
- }
39
- return
33
+ const bucket = this . byState [ bucketState ] as Set < string >
34
+ if ( bucketState === unlessState && bucket . has ( id ) ) {
35
+ return false
36
+ }
37
+ bucket . delete ( id )
38
+ if ( bucket . size === 0 ) {
39
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
40
+ delete this . byState [ bucketState ]
40
41
}
42
+ return true
41
43
}
44
+ return true
42
45
}
43
46
44
47
has ( id : string ) : boolean {
0 commit comments