4
4
ArrayPrototypeAt,
5
5
ArrayPrototypeIndexOf,
6
6
ArrayPrototypePush,
7
+ ArrayPrototypePushApply,
8
+ ArrayPrototypeSlice,
7
9
ArrayPrototypeSplice,
8
10
ObjectDefineProperty,
9
11
ObjectGetPrototypeOf,
@@ -97,6 +99,7 @@ function wrapStoreRun(store, data, next, transform = defaultTransform) {
97
99
class ActiveChannel {
98
100
subscribe ( subscription ) {
99
101
validateFunction ( subscription , 'subscription' ) ;
102
+ this . _subscribers = ArrayPrototypeSlice ( this . _subscribers ) ;
100
103
ArrayPrototypePush ( this . _subscribers , subscription ) ;
101
104
channels . incRef ( this . name ) ;
102
105
}
@@ -105,7 +108,10 @@ class ActiveChannel {
105
108
const index = ArrayPrototypeIndexOf ( this . _subscribers , subscription ) ;
106
109
if ( index === - 1 ) return false ;
107
110
108
- ArrayPrototypeSplice ( this . _subscribers , index , 1 ) ;
111
+ const before = ArrayPrototypeSlice ( this . _subscribers , 0 , index ) ;
112
+ const after = ArrayPrototypeSlice ( this . _subscribers , index + 1 ) ;
113
+ this . _subscribers = before ;
114
+ ArrayPrototypePushApply ( this . _subscribers , after ) ;
109
115
110
116
channels . decRef ( this . name ) ;
111
117
maybeMarkInactive ( this ) ;
@@ -137,9 +143,10 @@ class ActiveChannel {
137
143
}
138
144
139
145
publish ( data ) {
140
- for ( let i = 0 ; i < ( this . _subscribers ?. length || 0 ) ; i ++ ) {
146
+ const subscribers = this . _subscribers ;
147
+ for ( let i = 0 ; i < ( subscribers ?. length || 0 ) ; i ++ ) {
141
148
try {
142
- const onMessage = this . _subscribers [ i ] ;
149
+ const onMessage = subscribers [ i ] ;
143
150
onMessage ( data , this . name ) ;
144
151
} catch ( err ) {
145
152
process . nextTick ( ( ) => {
0 commit comments