File tree Expand file tree Collapse file tree 3 files changed +15
-4
lines changed
Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import {
1919 type Variables ,
2020} from './types'
2121import { append } from './utilities/append'
22+ import { filter } from './utilities/filter'
2223
2324export function createCassiopeia ( ) : Cassiopeia {
2425 const store : Store = {
@@ -28,7 +29,7 @@ export function createCassiopeia(): Cassiopeia {
2829 log : [ ] ,
2930 matcher : undefined ,
3031 state : TypeState . Locked ,
31- subscriptions : new Set ( ) ,
32+ subscriptions : [ ] ,
3233 }
3334
3435 const plugins : Plugin [ ] = [ ]
@@ -63,9 +64,13 @@ export function createCassiopeia(): Cassiopeia {
6364 store . state = TypeState . None
6465
6566 const subscribe = ( subscription : Subscription ) : Unsubscribe => {
66- store . subscriptions . add ( subscription )
67+ if ( ! store . subscriptions . includes ( subscription ) ) {
68+ store . subscriptions . push ( subscription )
69+ }
6770
68- return ( ) => store . subscriptions . delete ( subscription )
71+ return ( ) => {
72+ filter ( store . subscriptions , ( value ) => value !== subscription )
73+ }
6974 }
7075
7176 const cassiopeia : Cassiopeia = {
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ export interface Store {
7070 iterators : Iterators
7171 log : Action [ ]
7272 state : TypeState
73- subscriptions : Set < Subscription >
73+ subscriptions : Subscription [ ]
7474 matcher ?: Matcher
7575}
7676
Original file line number Diff line number Diff line change 1+ /**
2+ * Filters an array in-place by removing elements that don't match the predicate.
3+ * Iterates backwards through the array to avoid index shifting issues when removing elements.
4+ * @param array - The array to filter (mutated in place)
5+ * @param predicate - Function that returns true for elements to keep
6+ */
17export const filter = < T > ( array : T [ ] , predicate : ( value : T ) => boolean ) => {
28 for ( let l = array . length - 1 ; l >= 0 ; l -= 1 ) {
39 if ( ! predicate ( array [ l ] ) ) array . splice ( l , 1 )
You can’t perform that action at this time.
0 commit comments