Skip to content

Commit

Permalink
Sync v0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jan 10, 2025
1 parent 928ab51 commit 78f4fdb
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 67 deletions.
16 changes: 8 additions & 8 deletions packages/reactivity/src/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
import { activeEffectScope } from './effectScope'
import type { Ref } from './ref'
import {
type Dependency,
type IComputed,
type Link,
type IDependency,
type ILink,
SubscriberFlags,
endTrack,
isDirty,
Expand Down Expand Up @@ -59,13 +59,13 @@ export class ComputedRefImpl<T = any> implements IComputed {
*/
_value: T | undefined = undefined

// Dependency
subs: Link | undefined = undefined
subsTail: Link | undefined = undefined
// IDependency
subs: ILink | undefined = undefined
subsTail: ILink | undefined = undefined

// Subscriber
deps: Link | undefined = undefined
depsTail: Link | undefined = undefined
deps: ILink | undefined = undefined
depsTail: ILink | undefined = undefined
flags: SubscriberFlags = SubscriberFlags.Dirty

/**
Expand All @@ -84,7 +84,7 @@ export class ComputedRefImpl<T = any> implements IComputed {
return this
}
// for backwards compat
get dep(): Dependency {
get dep(): IDependency {
return this
}
// for backwards compat
Expand Down
8 changes: 4 additions & 4 deletions packages/reactivity/src/debug.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { extend } from '@vue/shared'
import type { DebuggerEventExtraInfo, ReactiveEffectOptions } from './effect'
import { type Link, type Subscriber, SubscriberFlags } from './system'
import { type ILink, type ISubscriber, SubscriberFlags } from './system'

export const triggerEventInfos: DebuggerEventExtraInfo[] = []

export function onTrack(
sub: Link['sub'],
sub: ILink['sub'],
debugInfo: DebuggerEventExtraInfo,
): void {
if (!__DEV__) {
Expand All @@ -25,7 +25,7 @@ export function onTrack(
}
}

export function onTrigger(sub: Link['sub']): void {
export function onTrigger(sub: ILink['sub']): void {
if (!__DEV__) {
throw new Error(
`Internal error: onTrigger should be called only in development.`,
Expand Down Expand Up @@ -61,7 +61,7 @@ export function setupOnTrigger(target: { new (...args: any[]): any }): void {
})
}

function setupFlagsHandler(target: Subscriber): void {
function setupFlagsHandler(target: ISubscriber): void {
;(target as any)._flags = target.flags
Object.defineProperty(target, 'flags', {
get() {
Expand Down
10 changes: 5 additions & 5 deletions packages/reactivity/src/dep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ import { onTrack, triggerEventInfos } from './debug'
import { activeSub } from './effect'
import {
type Dependency,
type Link,
type ILink,
endBatch,
link,
propagate,
startBatch,
} from './system'

class Dep implements Dependency {
_subs: Link | undefined = undefined
subsTail: Link | undefined = undefined
_subs: ILink | undefined = undefined
subsTail: ILink | undefined = undefined

constructor(
private map: KeyToDepMap,
private key: unknown,
) {}

get subs(): Link | undefined {
get subs(): ILink | undefined {
return this._subs
}

set subs(value: Link | undefined) {
set subs(value: ILink | undefined) {
this._subs = value
if (value === undefined) {
this.map.delete(this.key)
Expand Down
16 changes: 8 additions & 8 deletions packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { setupOnTrigger } from './debug'
import { activeEffectScope } from './effectScope'
import {
type IEffect,
type Link,
type Subscriber,
type ILink,
type ISubscriber,
SubscriberFlags,
endTrack,
isDirty,
Expand All @@ -16,7 +16,7 @@ import { warn } from './warning'
export type EffectScheduler = (...args: any[]) => any

export type DebuggerEvent = {
effect: Subscriber
effect: ISubscriber
} & DebuggerEventExtraInfo

export type DebuggerEventExtraInfo = {
Expand Down Expand Up @@ -57,8 +57,8 @@ export class ReactiveEffect<T = any> implements IEffect, ReactiveEffectOptions {
nextNotify: IEffect | undefined = undefined

// Subscriber
deps: Link | undefined = undefined
depsTail: Link | undefined = undefined
deps: ILink | undefined = undefined
depsTail: ILink | undefined = undefined
flags: number = SubscriberFlags.Dirty

/**
Expand Down Expand Up @@ -201,7 +201,7 @@ export function stop(runner: ReactiveEffectRunner): void {
runner.effect.stop()
}

const resetTrackingStack: (Subscriber | undefined)[] = []
const resetTrackingStack: (ISubscriber | undefined)[] = []

/**
* Temporarily pauses tracking.
Expand Down Expand Up @@ -288,8 +288,8 @@ function cleanupEffect(e: ReactiveEffect) {
}
}

export let activeSub: Subscriber | undefined = undefined
export let activeSub: ISubscriber | undefined = undefined

export function setActiveSub(sub: Subscriber | undefined): void {
export function setActiveSub(sub: ISubscriber | undefined): void {
activeSub = sub
}
10 changes: 5 additions & 5 deletions packages/reactivity/src/effectScope.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EffectFlags, type ReactiveEffect } from './effect'
import {
type Link,
type Subscriber,
type ILink,
type ISubscriber,
SubscriberFlags,
endTrack,
startTrack,
Expand All @@ -10,10 +10,10 @@ import { warn } from './warning'

export let activeEffectScope: EffectScope | undefined

export class EffectScope implements Subscriber {
export class EffectScope implements ISubscriber {
// Subscriber: In order to collect orphans computeds
deps: Link | undefined = undefined
depsTail: Link | undefined = undefined
deps: ILink | undefined = undefined
depsTail: ILink | undefined = undefined
flags: number = SubscriberFlags.None

/**
Expand Down
10 changes: 5 additions & 5 deletions packages/reactivity/src/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
toRaw,
toReactive,
} from './reactive'
import { type Dependency, type Link, link, propagate } from './system'
import { type Dependency, type ILink, link, propagate } from './system'
import { warn } from './warning'

declare const RefSymbol: unique symbol
Expand Down Expand Up @@ -110,8 +110,8 @@ function createRef(rawValue: unknown, shallow: boolean) {
*/
class RefImpl<T = any> implements Dependency {
// Dependency
subs: Link | undefined = undefined
subsTail: Link | undefined = undefined
subs: ILink | undefined = undefined
subsTail: ILink | undefined = undefined

_value: T
private _rawValue: T
Expand Down Expand Up @@ -297,8 +297,8 @@ export type CustomRefFactory<T> = (

class CustomRefImpl<T> implements Dependency {
// Dependency
subs: Link | undefined = undefined
subsTail: Link | undefined = undefined
subs: ILink | undefined = undefined
subsTail: ILink | undefined = undefined

private readonly _get: ReturnType<CustomRefFactory<T>>['get']
private readonly _set: ReturnType<CustomRefFactory<T>>['set']
Expand Down
64 changes: 32 additions & 32 deletions packages/reactivity/src/system.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
// Ported from https://github.com/stackblitz/alien-signals/blob/81b07f8313bc69662a5766543e84c6dd77238b6b/src/system.ts
// Ported from https://github.com/stackblitz/alien-signals/blob/v0.6.0/src/system.ts

export interface IEffect extends Subscriber {
export interface IEffect extends ISubscriber {
nextNotify: IEffect | undefined
notify(): void
}

export interface IComputed extends Dependency, Subscriber {
export interface IComputed extends IDependency, ISubscriber {
update(): boolean
}

export interface Dependency {
subs: Link | undefined
subsTail: Link | undefined
export interface IDependency {
subs: ILink | undefined
subsTail: ILink | undefined
}

export interface Subscriber {
export interface ISubscriber {
flags: SubscriberFlags
deps: Link | undefined
depsTail: Link | undefined
deps: ILink | undefined
depsTail: ILink | undefined
}

export interface Link {
dep: Dependency | IComputed | (Dependency & IEffect)
sub: Subscriber | IComputed | (Dependency & IEffect) | IEffect
export interface ILink {
dep: IDependency | IComputed | (IDependency & IEffect)
sub: ISubscriber | IComputed | (IDependency & IEffect) | IEffect
// Reuse to link prev stack in checkDirty
// Reuse to link prev stack in propagate
prevSub: Link | undefined
nextSub: Link | undefined
prevSub: ILink | undefined
nextSub: ILink | undefined
// Reuse to link next released link in linkPool
nextDep: Link | undefined
nextDep: ILink | undefined
}

export enum SubscriberFlags {
Expand All @@ -43,7 +43,7 @@ export enum SubscriberFlags {
let batchDepth = 0
let queuedEffects: IEffect | undefined
let queuedEffectsTail: IEffect | undefined
let linkPool: Link | undefined
let linkPool: ILink | undefined

export function startBatch(): void {
++batchDepth
Expand All @@ -70,7 +70,7 @@ function drainQueuedEffects(): void {
}
}

export function link(dep: Dependency, sub: Subscriber): void {
export function link(dep: IDependency, sub: ISubscriber): void {
const currentDep = sub.depsTail
if (currentDep !== undefined && currentDep.dep === dep) {
return
Expand All @@ -92,12 +92,12 @@ export function link(dep: Dependency, sub: Subscriber): void {
}

function linkNewDep(
dep: Dependency,
sub: Subscriber,
nextDep: Link | undefined,
depsTail: Link | undefined,
dep: IDependency,
sub: ISubscriber,
nextDep: ILink | undefined,
depsTail: ILink | undefined,
): void {
let newLink: Link
let newLink: ILink

if (linkPool !== undefined) {
newLink = linkPool
Expand Down Expand Up @@ -134,7 +134,7 @@ function linkNewDep(
}

// See https://github.com/stackblitz/alien-signals#about-propagate-and-checkdirty-functions
export function propagate(link: Link): void {
export function propagate(link: ILink): void {
let targetFlag = SubscriberFlags.Dirty
let subs = link
let stack = 0
Expand Down Expand Up @@ -165,9 +165,9 @@ export function propagate(link: Link): void {
) &&
isValidLink(link, sub) &&
((sub.flags = subFlags | SubscriberFlags.Recursed | targetFlag),
(sub as Dependency).subs !== undefined))
(sub as IDependency).subs !== undefined))
) {
const subSubs = (sub as Dependency).subs
const subSubs = (sub as IDependency).subs
if (subSubs !== undefined) {
if (subSubs.nextSub !== undefined) {
subSubs.prevSub = subs
Expand Down Expand Up @@ -232,7 +232,7 @@ export function propagate(link: Link): void {
}
}

export function shallowPropagate(link: Link): void {
export function shallowPropagate(link: ILink): void {
do {
const updateSub = link.sub
const updateSubFlags = updateSub.flags
Expand All @@ -247,7 +247,7 @@ export function shallowPropagate(link: Link): void {
} while (link !== undefined)
}

function isValidLink(subLink: Link, sub: Subscriber): boolean {
function isValidLink(subLink: ILink, sub: ISubscriber): boolean {
const depsTail = sub.depsTail
if (depsTail !== undefined) {
let link = sub.deps!
Expand All @@ -265,7 +265,7 @@ function isValidLink(subLink: Link, sub: Subscriber): boolean {
}

// See https://github.com/stackblitz/alien-signals#about-propagate-and-checkdirty-functions
export function checkDirty(link: Link): boolean {
export function checkDirty(link: ILink): boolean {
let stack = 0
let dirty: boolean

Expand Down Expand Up @@ -342,7 +342,7 @@ export function checkDirty(link: Link): boolean {
} while (true)
}

export function startTrack(sub: Subscriber): void {
export function startTrack(sub: ISubscriber): void {
sub.depsTail = undefined
sub.flags =
(sub.flags &
Expand All @@ -355,7 +355,7 @@ export function startTrack(sub: Subscriber): void {
SubscriberFlags.Tracking
}

export function endTrack(sub: Subscriber): void {
export function endTrack(sub: ISubscriber): void {
const depsTail = sub.depsTail
if (depsTail !== undefined) {
const nextDep = depsTail.nextDep
Expand All @@ -370,7 +370,7 @@ export function endTrack(sub: Subscriber): void {
sub.flags &= ~SubscriberFlags.Tracking
}

function clearTrack(link: Link): void {
function clearTrack(link: ILink): void {
do {
const dep = link.dep
const nextDep = link.nextDep
Expand Down Expand Up @@ -416,7 +416,7 @@ function clearTrack(link: Link): void {
} while (link !== undefined)
}

export function isDirty(sub: Subscriber, flags: SubscriberFlags): boolean {
export function isDirty(sub: ISubscriber, flags: SubscriberFlags): boolean {
if (flags & SubscriberFlags.Dirty) {
return true
} else if (flags & SubscriberFlags.ToCheckDirty) {
Expand Down

0 comments on commit 78f4fdb

Please sign in to comment.