Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(reactivity): sync alien-signals 1.0.4 changes #12791

Merged
merged 7 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions packages/reactivity/src/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ function setupFlagsHandler(target: Subscriber): void {
},
set(value) {
if (
!(
(target as any)._flags &
(SubscriberFlags.PendingComputed | SubscriberFlags.Dirty)
) &&
!!(value & (SubscriberFlags.PendingComputed | SubscriberFlags.Dirty))
!((target as any)._flags & SubscriberFlags.Propagated) &&
!!(value & SubscriberFlags.Propagated)
) {
onTrigger(this)
}
Expand Down
54 changes: 14 additions & 40 deletions packages/reactivity/src/system.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
// Ported from https://github.com/stackblitz/alien-signals/blob/v1.0.0/src/system.ts
// Ported from https://github.com/stackblitz/alien-signals/blob/v1.0.4/src/system.ts
import type { ComputedRefImpl as Computed } from './computed.js'
import type { ReactiveEffect as Effect } from './effect.js'

Expand Down Expand Up @@ -35,7 +35,6 @@ export const enum SubscriberFlags {
let batchDepth = 0
let queuedEffects: Effect | undefined
let queuedEffectsTail: Effect | undefined
let linkPool: Link | undefined

export function startBatch(): void {
++batchDepth
Expand Down Expand Up @@ -195,24 +194,18 @@ export function processComputedUpdate(
computed: Computed,
flags: SubscriberFlags,
): void {
if (flags & SubscriberFlags.Dirty) {
if (
flags & SubscriberFlags.Dirty ||
(checkDirty(computed.deps!)
? true
: ((computed.flags = flags & ~SubscriberFlags.PendingComputed), false))
) {
if (computed.update()) {
const subs = computed.subs
if (subs !== undefined) {
shallowPropagate(subs)
}
}
} else if (flags & SubscriberFlags.PendingComputed) {
if (checkDirty(computed.deps!)) {
if (computed.update()) {
const subs = computed.subs
if (subs !== undefined) {
shallowPropagate(subs)
}
}
} else {
computed.flags = flags & ~SubscriberFlags.PendingComputed
}
}
}

Expand All @@ -238,22 +231,12 @@ function linkNewDep(
nextDep: Link | undefined,
depsTail: Link | undefined,
): Link {
let newLink: Link

if (linkPool !== undefined) {
newLink = linkPool
linkPool = newLink.nextDep
newLink.nextDep = nextDep
newLink.dep = dep
newLink.sub = sub
} else {
newLink = {
dep,
sub,
nextDep,
prevSub: undefined,
nextSub: undefined,
}
const newLink: Link = {
dep,
sub,
nextDep,
prevSub: undefined,
nextSub: undefined,
}

if (depsTail === undefined) {
Expand Down Expand Up @@ -327,7 +310,7 @@ function checkDirty(link: Link): boolean {
if (sub.update()) {
if ((link = subSubs.prevSub!) !== undefined) {
subSubs.prevSub = undefined
shallowPropagate(sub.subs!)
shallowPropagate(subSubs)
sub = link.sub as Computed
} else {
sub = subSubs.sub as Computed
Expand Down Expand Up @@ -400,25 +383,16 @@ function clearTracking(link: Link): void {

if (nextSub !== undefined) {
nextSub.prevSub = prevSub
link.nextSub = undefined
} else {
dep.subsTail = prevSub
}

if (prevSub !== undefined) {
prevSub.nextSub = nextSub
link.prevSub = undefined
} else {
dep.subs = nextSub
}

// @ts-expect-error
link.dep = undefined
// @ts-expect-error
link.sub = undefined
link.nextDep = linkPool
linkPool = link

if (dep.subs === undefined && 'deps' in dep) {
const depFlags = dep.flags
if (!(depFlags & SubscriberFlags.Dirty)) {
Expand Down