setupで起きること
1
3. watchEffectが実⾏されてrefを参照してLink1が作られる。
(watchEffectの引数は即実⾏される)
ref
x
watchEffect
Link1
Slide 29
Slide 29 text
1. templateの描画が開始。
templateの描画で起きること
2
ref
x
watchEffect
Link1
Slide 30
Slide 30 text
2
2. templateがrefを参照してLink2が作られる。
Link1から⾒てLink2のtemplateはnextSub、逆はprevSub。
ref
x
watchEffect
Link1
ref
x
template
Link2
nextSub
prevSub
templateの描画で起きること
Slide 31
Slide 31 text
2
3. templateがcomputedを参照してLink3が作られる。computedはここで算出
Link2から⾒てLink3のcomputedはnextDep、逆はprevDep。
ref
x
watchEffect
Link1
ref
x
template
Link2 computed
x
template
Link3
nextSub
prevSub
prevDep
nextDep
templateの描画で起きること
Slide 32
Slide 32 text
2
4. computedがrefを参照してLink4が作られる。
Link2から⾒てLink4のcomputedはnextSub、逆はprevSub
ref
x
watchEffect
Link1
ref
x
template
Link2 computed
x
template
Link3
ref
x
computed
Link
4
nextSub
prevSub
nextSub
prevSub
prevDep
nextDep
templateの描画で起きること
Slide 33
Slide 33 text
これでsetupとtemplateの初期化終わり
次はリアクティブの更新!
Slide 34
Slide 34 text
refの更新で起きること
3
1. ボタンクリックでrefが更新される。
ref
x
watchEffect
Link1
ref
x
template
Link2 computed
x
template
Link3
ref
x
computed
Link4
nextSub
prevSub
nextSub
prevSub
prevDep
nextDep
Slide 35
Slide 35 text
2. refの更新が末尾のLink4のSubに通知される。
refの更新で起きること
3
ref
x
watchEffect
Link1
ref
x
template
Link2 computed
x
template
Link3
ref
x
computed
Link
4
nextSub
prevSub
nextSub
prevSub
prevDep
nextDep
Slide 36
Slide 36 text
3. Link4からprevSubを辿って、先頭のLink1のSubが
実⾏する処理をキューに⼊れる。
refの更新で起きること
3
ref
x
watchEffect
Link1
ref
x
template
Link2 computed
x
template
Link3
ref
x
computed
Link4
Queue
Link1の処理
nextSub
prevSub
nextSub
prevSub
prevDep
nextDep
ref ref ref
Slide 37
Slide 37 text
3. Link4からprevSubを辿って、先頭のLink1のSubが
実⾏する処理をキューに⼊れる。
refの更新で起きること
3
ref
x
watchEffect
Link1
ref
x
template
Link2 computed
x
template
Link3
ref
x
computed
Link4
Queue
Link1の処理
nextSub
prevSub
nextSub
prevSub
prevDep
nextDep
ref ref ref
満を持してキューが登場
Slide 38
Slide 38 text
refの更新で起きること
3
4. Link2のSubが実⾏する処理をキューに⼊れる。
ref
x
watchEffect
Link1
ref
x
template
Link2 computed
x
template
Link3
ref
x
computed
Link4
Link2の処理
Queue
Link1の処理
nextSub
prevSub
nextSub
prevSub
prevDep
nextDep
Slide 39
Slide 39 text
refの更新で起きること
3
5. Link4のSubはcomputedなので後で実⾏する。
ref
x
watchEffect
Link1
ref
x
template
Link2 computed
x
template
Link3
ref
x
computed
Link
4
Queue
Link2の処理 Link1の処理
nextSub
prevSub
nextSub
prevSub
prevDep
nextDep
Slide 40
Slide 40 text
再描画で起きること
4
1. ⾮同期でキューを順番に実⾏する。
まずはwatchEffectが実⾏。
ref
x
watchEffect
Link1
ref
x
template
Link2 computed
x
template
Link3
ref
x
computed
Link4
Queue
Link2の処理 Link1の処理
nextSub
prevSub
nextSub
prevSub
prevDep
nextDep
Slide 41
Slide 41 text
再描画で起きること
4
2. 次にtemplateの描画が再実⾏。
ref
x
watchEffect
Link1
ref
x
template
Link2 computed
x
template
Link3
ref
x
computed
Link4
Queue
Link2の処理
nextSub
prevSub
nextSub
prevSub
prevDep
nextDep
Slide 42
Slide 42 text
再描画で起きること
4
3. templateがLink2のDepのrefを参照する。
ref
x
watchEffect
Link1
ref
x
template
Link2 computed
x
template
Link3
ref
x
computed
Link4
Queue
nextSub
prevSub
nextSub
prevSub
prevDep
nextDep
Slide 43
Slide 43 text
再描画で起きること
4
4. templateがLink3のDepのcomputedを参照する。
ここでcomputedが再計算!
ref
x
watchEffect
Link1
ref
x
template
Link2 computed
x
template
Link3
ref
x
computed
Link4
Queue
nextSub
prevSub
nextSub
prevSub
prevDep
nextDep
Slide 44
Slide 44 text
再描画で起きること
4
5. なんやかんやでtemplateの再描画が終わる。
ref
x
watchEffect
Link1
ref
x
template
Link2 computed
x
template
Link3
ref
x
computed
Link4
Queue
nextSub
prevSub
nextSub
prevSub
prevDep
nextDep
Slide 45
Slide 45 text
めでたしめでたし🎉
Slide 46
Slide 46 text
Link(リンクリスト)の何が嬉しいのか
● Linkのデータ構造はVue 3.5から登場しました。3.6でも使われる予定。
○ Refactor reactivity system to use version counting and doubly-linked list tracking #10397
○ ↑3.5でメモリ効率とパフォーマンスがめっちゃ良くなったPR。3.6で更に良くなる!
● 誰がどこにどの順番で依存しているかわかる。
● リアクティブな状態の依存関係は変わりうるので、変わったときでもO(1)の
計算量でリンクの追加削除ができる。