|
|
@@ -234,9 +234,15 @@ export class ReactiveEffect<T = any>
|
|
|
|
|
|
let batchDepth = 0
|
|
|
let batchedSub: Subscriber | undefined
|
|
|
+let batchedComputed: Subscriber | undefined
|
|
|
|
|
|
-export function batch(sub: Subscriber): void {
|
|
|
+export function batch(sub: Subscriber, isComputed = false): void {
|
|
|
sub.flags |= EffectFlags.NOTIFIED
|
|
|
+ if (isComputed) {
|
|
|
+ sub.next = batchedComputed
|
|
|
+ batchedComputed = sub
|
|
|
+ return
|
|
|
+ }
|
|
|
sub.next = batchedSub
|
|
|
batchedSub = sub
|
|
|
}
|
|
|
@@ -257,24 +263,23 @@ export function endBatch(): void {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ if (batchedComputed) {
|
|
|
+ let e: Subscriber | undefined = batchedComputed
|
|
|
+ batchedComputed = undefined
|
|
|
+ while (e) {
|
|
|
+ const next: Subscriber | undefined = e.next
|
|
|
+ e.next = undefined
|
|
|
+ e.flags &= ~EffectFlags.NOTIFIED
|
|
|
+ e = next
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
let error: unknown
|
|
|
while (batchedSub) {
|
|
|
let e: Subscriber | undefined = batchedSub
|
|
|
- let next: Subscriber | undefined
|
|
|
- // 1st pass: clear notified flags for computed upfront
|
|
|
- // we use the ACTIVE flag as a discriminator between computed and effect,
|
|
|
- // since NOTIFIED is useless for an inactive effect anyway.
|
|
|
- while (e) {
|
|
|
- if (!(e.flags & EffectFlags.ACTIVE)) {
|
|
|
- e.flags &= ~EffectFlags.NOTIFIED
|
|
|
- }
|
|
|
- e = e.next
|
|
|
- }
|
|
|
- e = batchedSub
|
|
|
batchedSub = undefined
|
|
|
- // 2nd pass: run effects
|
|
|
while (e) {
|
|
|
- next = e.next
|
|
|
+ const next: Subscriber | undefined = e.next
|
|
|
e.next = undefined
|
|
|
e.flags &= ~EffectFlags.NOTIFIED
|
|
|
if (e.flags & EffectFlags.ACTIVE) {
|