@@ -4,7 +4,7 @@ import { type TrackOpTypes, TriggerOpTypes } from './constants'
44import {
55 type DebuggerEventExtraInfo ,
66 EffectFlags ,
7- type Link ,
7+ type Subscriber ,
88 activeSub ,
99 endBatch ,
1010 shouldTrack ,
@@ -18,6 +18,49 @@ import {
1818 */
1919export let globalVersion = 0
2020
21+ /**
22+ * Represents a link between a source (Dep) and a subscriber (Effect or Computed).
23+ * Deps and subs have a many-to-many relationship - each link between a
24+ * dep and a sub is represented by a Link instance.
25+ *
26+ * A Link is also a node in two doubly-linked lists - one for the associated
27+ * sub to track all its deps, and one for the associated dep to track all its
28+ * subs.
29+ *
30+ * @internal
31+ */
32+ export class Link {
33+ /**
34+ * - Before each effect run, all previous dep links' version are reset to -1
35+ * - During the run, a link's version is synced with the source dep on access
36+ * - After the run, links with version -1 (that were never used) are cleaned
37+ * up
38+ */
39+ version : number
40+
41+ /**
42+ * Pointers for doubly-linked lists
43+ */
44+ nextDep ?: Link
45+ prevDep ?: Link
46+ nextSub ?: Link
47+ prevSub ?: Link
48+ prevActiveLink ?: Link
49+
50+ constructor (
51+ public sub : Subscriber ,
52+ public dep : Dep ,
53+ ) {
54+ this . version = dep . version
55+ this . nextDep =
56+ this . prevDep =
57+ this . nextSub =
58+ this . prevSub =
59+ this . prevActiveLink =
60+ undefined
61+ }
62+ }
63+
2164/**
2265 * @internal
2366 */
@@ -52,16 +95,7 @@ export class Dep {
5295
5396 let link = this . activeLink
5497 if ( link === undefined || link . sub !== activeSub ) {
55- link = this . activeLink = {
56- dep : this ,
57- sub : activeSub ,
58- version : this . version ,
59- nextDep : undefined ,
60- prevDep : undefined ,
61- nextSub : undefined ,
62- prevSub : undefined ,
63- prevActiveLink : undefined ,
64- }
98+ link = this . activeLink = new Link ( activeSub , this )
6599
66100 // add the link to the activeEffect as a dep (as tail)
67101 if ( ! activeSub . deps ) {
0 commit comments