|
1 | 1 | /* eslint-disable */
|
2 |
| -// Ported from https://github.com/stackblitz/alien-signals/blob/4962714dadd133cee16060eb4eb99b90e9e6052d/src/system.ts |
| 2 | +// Ported from https://github.com/stackblitz/alien-signals/blob/v1.0.10/src/system.ts |
3 | 3 | import type { ComputedRefImpl as Computed } from './computed.js'
|
4 | 4 | import type { ReactiveEffect as Effect } from './effect.js'
|
5 | 5 |
|
@@ -37,9 +37,11 @@ interface OneWayLink<T> {
|
37 | 37 | linked: OneWayLink<T> | undefined
|
38 | 38 | }
|
39 | 39 |
|
| 40 | +const notifyBuffer: (Effect | undefined)[] = [] |
| 41 | + |
40 | 42 | let batchDepth = 0
|
41 |
| -let queuedEffects: OneWayLink<Effect> | undefined |
42 |
| -let queuedEffectsTail: OneWayLink<Effect> | undefined |
| 43 | +let notifyIndex = 0 |
| 44 | +let notifyBufferLength = 0 |
43 | 45 |
|
44 | 46 | export function startBatch(): void {
|
45 | 47 | ++batchDepth
|
@@ -121,17 +123,7 @@ export function propagate(current: Link): void {
|
121 | 123 | continue
|
122 | 124 | }
|
123 | 125 | if (subFlags & SubscriberFlags.Effect) {
|
124 |
| - if (queuedEffectsTail !== undefined) { |
125 |
| - queuedEffectsTail = queuedEffectsTail.linked = { |
126 |
| - target: sub as Effect, |
127 |
| - linked: undefined, |
128 |
| - } |
129 |
| - } else { |
130 |
| - queuedEffectsTail = queuedEffects = { |
131 |
| - target: sub as Effect, |
132 |
| - linked: undefined, |
133 |
| - } |
134 |
| - } |
| 126 | + notifyBuffer[notifyBufferLength++] = sub as Effect |
135 | 127 | }
|
136 | 128 | } else if (!(subFlags & (SubscriberFlags.Tracking | targetFlag))) {
|
137 | 129 | sub.flags = subFlags | targetFlag
|
@@ -223,14 +215,13 @@ export function processComputedUpdate(
|
223 | 215 | }
|
224 | 216 |
|
225 | 217 | export function processEffectNotifications(): void {
|
226 |
| - while (queuedEffects !== undefined) { |
227 |
| - const effect = queuedEffects.target |
228 |
| - queuedEffects = queuedEffects.linked |
229 |
| - if (queuedEffects === undefined) { |
230 |
| - queuedEffectsTail = undefined |
231 |
| - } |
| 218 | + while (notifyIndex < notifyBufferLength) { |
| 219 | + const effect = notifyBuffer[notifyIndex]! |
| 220 | + notifyBuffer[notifyIndex++] = undefined |
232 | 221 | effect.notify()
|
233 | 222 | }
|
| 223 | + notifyIndex = 0 |
| 224 | + notifyBufferLength = 0 |
234 | 225 | }
|
235 | 226 |
|
236 | 227 | function linkNewDep(
|
|
0 commit comments