Skip to content

Commit cc994e0

Browse files
committed
sync 1.0.10
1 parent 9f97d98 commit cc994e0

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

packages/reactivity/src/system.ts

Lines changed: 11 additions & 20 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/4962714dadd133cee16060eb4eb99b90e9e6052d/src/system.ts
2+
// Ported from https://github.com/stackblitz/alien-signals/blob/v1.0.10/src/system.ts
33
import type { ComputedRefImpl as Computed } from './computed.js'
44
import type { ReactiveEffect as Effect } from './effect.js'
55

@@ -37,9 +37,11 @@ interface OneWayLink<T> {
3737
linked: OneWayLink<T> | undefined
3838
}
3939

40+
const notifyBuffer: (Effect | undefined)[] = []
41+
4042
let batchDepth = 0
41-
let queuedEffects: OneWayLink<Effect> | undefined
42-
let queuedEffectsTail: OneWayLink<Effect> | undefined
43+
let notifyIndex = 0
44+
let notifyBufferLength = 0
4345

4446
export function startBatch(): void {
4547
++batchDepth
@@ -121,17 +123,7 @@ export function propagate(current: Link): void {
121123
continue
122124
}
123125
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
135127
}
136128
} else if (!(subFlags & (SubscriberFlags.Tracking | targetFlag))) {
137129
sub.flags = subFlags | targetFlag
@@ -223,14 +215,13 @@ export function processComputedUpdate(
223215
}
224216

225217
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
232221
effect.notify()
233222
}
223+
notifyIndex = 0
224+
notifyBufferLength = 0
234225
}
235226

236227
function linkNewDep(

0 commit comments

Comments
 (0)