Skip to content

Commit 1ac0499

Browse files
refactor(reactivity): sync alien-signals 1.0.4 changes (#12791)
1 parent 84663cc commit 1ac0499

File tree

2 files changed

+16
-45
lines changed

2 files changed

+16
-45
lines changed

packages/reactivity/src/debug.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,8 @@ function setupFlagsHandler(target: Subscriber): void {
6969
},
7070
set(value) {
7171
if (
72-
!(
73-
(target as any)._flags &
74-
(SubscriberFlags.PendingComputed | SubscriberFlags.Dirty)
75-
) &&
76-
!!(value & (SubscriberFlags.PendingComputed | SubscriberFlags.Dirty))
72+
!((target as any)._flags & SubscriberFlags.Propagated) &&
73+
!!(value & SubscriberFlags.Propagated)
7774
) {
7875
onTrigger(this)
7976
}

packages/reactivity/src/system.ts

+14-40
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.0/src/system.ts
2+
// Ported from https://github.com/stackblitz/alien-signals/blob/v1.0.4/src/system.ts
33
import type { ComputedRefImpl as Computed } from './computed.js'
44
import type { ReactiveEffect as Effect } from './effect.js'
55

@@ -35,7 +35,6 @@ export const enum SubscriberFlags {
3535
let batchDepth = 0
3636
let queuedEffects: Effect | undefined
3737
let queuedEffectsTail: Effect | undefined
38-
let linkPool: Link | undefined
3938

4039
export function startBatch(): void {
4140
++batchDepth
@@ -195,24 +194,18 @@ export function processComputedUpdate(
195194
computed: Computed,
196195
flags: SubscriberFlags,
197196
): void {
198-
if (flags & SubscriberFlags.Dirty) {
197+
if (
198+
flags & SubscriberFlags.Dirty ||
199+
(checkDirty(computed.deps!)
200+
? true
201+
: ((computed.flags = flags & ~SubscriberFlags.PendingComputed), false))
202+
) {
199203
if (computed.update()) {
200204
const subs = computed.subs
201205
if (subs !== undefined) {
202206
shallowPropagate(subs)
203207
}
204208
}
205-
} else if (flags & SubscriberFlags.PendingComputed) {
206-
if (checkDirty(computed.deps!)) {
207-
if (computed.update()) {
208-
const subs = computed.subs
209-
if (subs !== undefined) {
210-
shallowPropagate(subs)
211-
}
212-
}
213-
} else {
214-
computed.flags = flags & ~SubscriberFlags.PendingComputed
215-
}
216209
}
217210
}
218211

@@ -238,22 +231,12 @@ function linkNewDep(
238231
nextDep: Link | undefined,
239232
depsTail: Link | undefined,
240233
): Link {
241-
let newLink: Link
242-
243-
if (linkPool !== undefined) {
244-
newLink = linkPool
245-
linkPool = newLink.nextDep
246-
newLink.nextDep = nextDep
247-
newLink.dep = dep
248-
newLink.sub = sub
249-
} else {
250-
newLink = {
251-
dep,
252-
sub,
253-
nextDep,
254-
prevSub: undefined,
255-
nextSub: undefined,
256-
}
234+
const newLink: Link = {
235+
dep,
236+
sub,
237+
nextDep,
238+
prevSub: undefined,
239+
nextSub: undefined,
257240
}
258241

259242
if (depsTail === undefined) {
@@ -327,7 +310,7 @@ function checkDirty(link: Link): boolean {
327310
if (sub.update()) {
328311
if ((link = subSubs.prevSub!) !== undefined) {
329312
subSubs.prevSub = undefined
330-
shallowPropagate(sub.subs!)
313+
shallowPropagate(subSubs)
331314
sub = link.sub as Computed
332315
} else {
333316
sub = subSubs.sub as Computed
@@ -400,25 +383,16 @@ function clearTracking(link: Link): void {
400383

401384
if (nextSub !== undefined) {
402385
nextSub.prevSub = prevSub
403-
link.nextSub = undefined
404386
} else {
405387
dep.subsTail = prevSub
406388
}
407389

408390
if (prevSub !== undefined) {
409391
prevSub.nextSub = nextSub
410-
link.prevSub = undefined
411392
} else {
412393
dep.subs = nextSub
413394
}
414395

415-
// @ts-expect-error
416-
link.dep = undefined
417-
// @ts-expect-error
418-
link.sub = undefined
419-
link.nextDep = linkPool
420-
linkPool = link
421-
422396
if (dep.subs === undefined && 'deps' in dep) {
423397
const depFlags = dep.flags
424398
if (!(depFlags & SubscriberFlags.Dirty)) {

0 commit comments

Comments
 (0)