Skip to content

Commit 432b53b

Browse files
committed
sync 1.0.6
1 parent c9a2799 commit 432b53b

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

packages/reactivity/src/system.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable */
2-
// Ported from https://github.com/stackblitz/alien-signals/blob/v1.0.5/src/system.ts
2+
// Ported from https://github.com/stackblitz/alien-signals/blob/v1.0.6/src/system.ts
33
import type { ComputedRefImpl as Computed } from './computed.js'
44
import type { ReactiveEffect as Effect } from './effect.js'
55

@@ -32,9 +32,14 @@ export const enum SubscriberFlags {
3232
Propagated = Dirty | PendingComputed,
3333
}
3434

35-
let batchDepth = 0
35+
interface QueuedLink {
36+
effect: Effect
37+
next: QueuedLink | undefined
38+
}
3639

37-
const queuedEffects: Effect[] = []
40+
let batchDepth = 0
41+
let queuedEffects: QueuedLink | undefined
42+
let queuedEffectsTail: QueuedLink | undefined
3843

3944
export function startBatch(): void {
4045
++batchDepth
@@ -107,7 +112,17 @@ export function propagate(link: Link): void {
107112
continue
108113
}
109114
if (subFlags & SubscriberFlags.Effect) {
110-
queuedEffects.push(sub as Effect)
115+
if (queuedEffectsTail !== undefined) {
116+
queuedEffectsTail = queuedEffectsTail.next = {
117+
effect: sub as Effect,
118+
next: undefined,
119+
}
120+
} else {
121+
queuedEffectsTail = queuedEffects = {
122+
effect: sub as Effect,
123+
next: undefined,
124+
}
125+
}
111126
}
112127
} else if (!(subFlags & (SubscriberFlags.Tracking | targetFlag))) {
113128
sub.flags = subFlags | targetFlag
@@ -205,8 +220,13 @@ export function processComputedUpdate(
205220
}
206221

207222
export function processEffectNotifications(): void {
208-
while (queuedEffects.length) {
209-
queuedEffects.shift()!.notify()
223+
while (queuedEffects !== undefined) {
224+
const effect = queuedEffects.effect
225+
queuedEffects = queuedEffects.next
226+
if (queuedEffects === undefined) {
227+
queuedEffectsTail = undefined
228+
}
229+
effect.notify()
210230
}
211231
}
212232

0 commit comments

Comments
 (0)