@@ -4,7 +4,7 @@ import { type TrackOpTypes, TriggerOpTypes } from './constants'
4
4
import {
5
5
type DebuggerEventExtraInfo ,
6
6
EffectFlags ,
7
- type Link ,
7
+ type Subscriber ,
8
8
activeSub ,
9
9
endBatch ,
10
10
shouldTrack ,
@@ -18,6 +18,49 @@ import {
18
18
*/
19
19
export let globalVersion = 0
20
20
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
+
21
64
/**
22
65
* @internal
23
66
*/
@@ -52,16 +95,7 @@ export class Dep {
52
95
53
96
let link = this . activeLink
54
97
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 )
65
99
66
100
// add the link to the activeEffect as a dep (as tail)
67
101
if ( ! activeSub . deps ) {
0 commit comments