@aiquants/period-slider 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +137 -0
- package/README.md +22 -5
- package/dist/VirtualDateDropdown.d.ts +10 -0
- package/dist/VirtualDateDropdown.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +2753 -2298
- package/dist/renderScope.d.ts +486 -0
- package/dist/renderScope.d.ts.map +1 -0
- package/dist/selectorMemo.d.ts +12 -0
- package/dist/selectorMemo.d.ts.map +1 -1
- package/dist/useCommittedRef.d.ts +64 -79
- package/dist/useCommittedRef.d.ts.map +1 -1
- package/dist/usePeriodSlider.d.ts +56 -12
- package/dist/usePeriodSlider.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/VirtualDateDropdown.tsx +61 -6
- package/src/renderScope.ts +766 -0
- package/src/selectorMemo.ts +12 -0
- package/src/useCommittedRef.ts +51 -163
- package/src/usePeriodSlider.ts +252 -104
package/src/selectorMemo.ts
CHANGED
|
@@ -67,6 +67,18 @@ export const selectorUnitKey = (date: Date, unit: PeriodSliderUnit, yearStartMon
|
|
|
67
67
|
* 両境界をそのキーで比べる。制御中は `initialDate` を描かないため動きは比べないが、使えない値を渡した描画は省かない
|
|
68
68
|
* (セレクタは毎描画ですべての Date 型 Props を検証する)。
|
|
69
69
|
*
|
|
70
|
+
* One call runs `keyOf` once for each Date value it reads (the shown date, minDate and maxDate of each render, and the next render's
|
|
71
|
+
* initialDate when that render is controlled) and stops at the first check that fails, so it keys at most seven values whatever the
|
|
72
|
+
* range or the candidate lists (the selectors' `keyOf` runs keyInsideDateRange once per value, and up to twice for
|
|
73
|
+
* `DateSelector variant="split-dropdown"`, which also keys the year). No key is kept between calls: a key cached for a Date object
|
|
74
|
+
* outlives an in-place change of that Date and would skip the render whose validation throws, and a key kept from the previous call
|
|
75
|
+
* may belong to another instance, since one comparator serves every instance, or to a render React discarded.
|
|
76
|
+
* 1 回の呼び出しは、読む Date の値 1 つにつき `keyOf` を 1 回呼び (前回と今回の描画の表示する日付・minDate・maxDate と、今回の描画が制御中なら
|
|
77
|
+
* その initialDate)、最初に成り立たない判定で打ち切る。キー化は範囲や候補の一覧に依らず高々 7 回 (セレクタの `keyOf` は値 1 つにつき
|
|
78
|
+
* keyInsideDateRange を 1 回、年もキーにする `DateSelector variant="split-dropdown"` は高々 2 回呼ぶ)。キーは呼び出しをまたいで保持しない
|
|
79
|
+
* (Date を鍵にしたキャッシュは、その場で書き換えた Date に書き換え前のキーを返して検証が送出する描画を省かせ、前回の呼び出しのキーは、
|
|
80
|
+
* 比較器が全インスタンスで共有されるため別のインスタンスのものにも、React が捨てた描画のものにもなり得る)。
|
|
81
|
+
*
|
|
70
82
|
* @param prev - Props of the previous render / 前回の描画の Props
|
|
71
83
|
* @param next - Props of the next render / 今回の描画の Props
|
|
72
84
|
* @param keyOf - Unit key of a valid Date: the selector's `selectorUnitKey` closure, the key its uncontrolled selection adopts by / 有効な Date の単位のキー (セレクタの `selectorUnitKey` のクロージャ。非制御の選択が取り込みを決めるキーと同じ)
|
package/src/useCommittedRef.ts
CHANGED
|
@@ -1,113 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview The one channel through which a state hook hands the values of its committed render to the functions it returns (and a component to its own functions that outlive their render)
|
|
3
|
-
* 状態フックが確定した描画の値を返す関数へ渡す唯一の経路 (コンポーネントが描画より長く生きる自分の関数へ渡す経路でもある)
|
|
2
|
+
* @fileoverview The one channel through which a state hook hands the values of its committed render to the functions it returns (and a component to its own functions that outlive their render).
|
|
3
|
+
* 状態フックが確定した描画の値を返す関数へ渡す唯一の経路 (コンポーネントが描画より長く生きる自分の関数へ渡す経路でもある)。
|
|
4
4
|
*
|
|
5
|
-
* Internal module: not exported from the package entry. It imports only React, so `usePeriodSlider.ts`, `
|
|
6
|
-
* and `VirtualDateDropdown.tsx` can use it without an import cycle.
|
|
7
|
-
* 内部モジュール (パッケージの入口からは公開しない)。React だけを読み込むため、`usePeriodSlider.ts`・`selectorStep.ts`・`VirtualDateDropdown.tsx` が循環なしで使える。
|
|
5
|
+
* Internal module: not exported from the package entry. It imports only React, so `usePeriodSlider.ts`, `renderScope.ts`,
|
|
6
|
+
* `selectorStep.ts` and `VirtualDateDropdown.tsx` can use it without an import cycle.
|
|
7
|
+
* 内部モジュール (パッケージの入口からは公開しない)。React だけを読み込むため、`usePeriodSlider.ts`・`renderScope.ts`・`selectorStep.ts`・`VirtualDateDropdown.tsx` が循環なしで使える。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type React from "react"
|
|
11
11
|
import { useInsertionEffect, useState } from "react"
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* Only state mirrors use the record. Every hand-off a returned function makes is a plain value, never an updater, and
|
|
18
|
-
* React applies a hook's updates in the order they were queued, so while the record names the state's last queued
|
|
19
|
-
* update, the stored state ends at the recorded object. The one updater a hook's state receives is the hook's record of
|
|
20
|
-
* its own re-placement (recordPlacement), which clears the record first, because that updater may resolve to an earlier
|
|
21
|
-
* hand-off instead of the value it carries.
|
|
22
|
-
* 記録を使うのはステートの写しだけ。返す関数の受け渡しはすべて値そのもので (関数形の更新ではない)、React はフックの更新を積んだ順に
|
|
23
|
-
* 当てるため、記録がステートの最後に積んだ更新を指している間は、保存されるステートが記録したオブジェクトに行き着く。フックのステートが
|
|
24
|
-
* 受け取る更新関数はフック自身の収め直しの記録 (recordPlacement) だけで、それは先に記録を消す (その更新関数は運ぶ値ではなく前の受け渡しへ解け得るため)。
|
|
25
|
-
*/
|
|
26
|
-
export interface CommittedRef<T> extends React.RefObject<T> {
|
|
27
|
-
/**
|
|
28
|
-
* Records the object a returned function is about to pass to the mirrored state's setter.
|
|
29
|
-
* 返す関数が写すステートの設定関数へ渡そうとしているオブジェクトの記録。
|
|
30
|
-
*
|
|
31
|
-
* @param value - The object about to be handed over / これから渡すオブジェクト
|
|
32
|
-
* @returns Nothing / なし
|
|
33
|
-
*/
|
|
34
|
-
hand(value: T): void
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Whether the ref holds the recorded object, so the state's last queued update, or its stored value, already is the held object.
|
|
38
|
-
* ref が記録したオブジェクトを持つか (ステートの最後に積んだ更新、または保存済みの値が、既に保持するオブジェクトそのものか)。
|
|
39
|
-
*/
|
|
40
|
-
readonly holdsHanded: boolean
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Drops the record, so the next commit path that settles on the held value hands it over again.
|
|
44
|
-
* 記録を消す関数 (次に保持する値へ落ち着いた確定経路は、もう一度それを渡す)。
|
|
45
|
-
*
|
|
46
|
-
* The hook's record of its own re-placement (recordPlacement) calls it before it queues its updater, because that
|
|
47
|
-
* updater may resolve to a hand-off queued before it rather than to the placed value the mirror holds.
|
|
48
|
-
* フック自身の収め直しの記録 (recordPlacement) が更新関数を積む前に呼ぶ (その更新関数は、写しが持つ置いた値ではなく、前に積まれた受け渡しへ解け得るため)。
|
|
49
|
-
*
|
|
50
|
-
* @returns Nothing / なし
|
|
51
|
-
*/
|
|
52
|
-
forgetHanded(): void
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Drops the record unless it is the state object the running render pass holds; the hook body calls it right after it creates the mirror.
|
|
56
|
-
* 記録が、いま走っている描画の持つステートのオブジェクトでなければ記録を消す関数 (フック本体が写しを作った直後に呼ぶ)。
|
|
57
|
-
*
|
|
58
|
-
* A recorded hand-off stops being the state's last queued update in one way that shows in the next render of the hook:
|
|
59
|
-
* a hand-off made during a render (a returned function called from the host's render body) leaves the queue with that
|
|
60
|
-
* render when React throws the render away, and the restarted render holds an older state. The state this render pass
|
|
61
|
-
* holds is then not the recorded object, so the record is dropped and the next equal value is handed over again. A
|
|
62
|
-
* hook's state is a reducer whose setter has no eager path (useHookState in usePeriodSlider.ts), so the state that
|
|
63
|
-
* discarded render computed is never the base a later hand-off is compared with. The hook's record of its own
|
|
64
|
-
* re-placement clears the record and never leaves it stale.
|
|
65
|
-
* Until the hook renders again the record stands, so an equal call made between React throwing such a render away and
|
|
66
|
-
* the next render of the hook is skipped. A later render that hands the value over again stores it (the restarted
|
|
67
|
-
* render of a transition that still calls the function); when none does (a transition reverted before it commits), the
|
|
68
|
-
* call draws and notifies nothing. While Suspense keeps a transition held, React renders it again and throws it away
|
|
69
|
-
* after every commit, and the host's render-phase call hands the same value over again: the mirror, this record and the
|
|
70
|
-
* hook's known value keep returning to that value until the transition commits or is reverted, so shifts step from it
|
|
71
|
-
* and a commit-path call with that value is neither drawn nor notified. A render that skips the recorded update because
|
|
72
|
-
* of its lower priority drops the record too, which costs one more hand-off of an equal value, at the caller's priority.
|
|
73
|
-
* A hand-off made while handling an event never leaves the queue before it is applied. The write only ever deletes:
|
|
74
|
-
* made in a render that never commits, it can only add a hand-off, never cause one to be skipped.
|
|
75
|
-
* 記録した受け渡しがステートの最後に積んだ更新でなくなる道は 1 つで、次のフックの描画に現れる。描画の中で行った受け渡し (ホストの描画本体から
|
|
76
|
-
* 呼んだ返す関数) は、React がその描画を捨てると描画とともにキューから消え、やり直す描画は古いステートを持つ。このときこの描画が持つステートは
|
|
77
|
-
* 記録したオブジェクトではないため、記録を消し、次の同じ値はもう一度渡す。フックのステートは即時の経路を持たない設定関数のリデューサー
|
|
78
|
-
* (usePeriodSlider.ts の useHookState) のため、捨てた描画が求めたステートが後の受け渡しの比較の基準になることはない。
|
|
79
|
-
* フック自身の収め直しの記録は記録を消すため、記録を古くしない。次にフックを描くまでは記録が残るため、React がそうした描画を捨ててから
|
|
80
|
-
* 次にフックを描くまでの同じ値の呼び出しは省かれる。値を保存するのは、それをもう一度渡す後の描画 (まだ関数を呼ぶ移行のやり直し) だけで、
|
|
81
|
-
* 渡す描画が無ければ (確定する前に取り消した移行)、その呼び出しは何も描かず、何も通知しない。Suspense が移行を保留している間は、
|
|
82
|
-
* React が確定のたびにその移行を描き直して捨て、ホストの描画中の呼び出しが同じ値を渡し直すため、写し・この記録・フックの知っている値は、
|
|
83
|
-
* その移行が確定するか取り消されるまでその値に戻り続ける (シフトはそこから進み、その値と同じ確定経路の呼び出しは描かれず、通知もされない)。
|
|
84
|
-
* 記録した更新を優先度が低いために飛ばした描画も記録を消すが、同じ値の受け渡しが呼び出し側の優先度で 1 度増えるだけである。
|
|
85
|
-
* 事象の処理中に行った受け渡しは、当てられる前にキューから消えることがない。この書き込みは消すだけで、確定しない描画で行っても
|
|
86
|
-
* 受け渡しが増えるだけであり、省く判断は生まない。
|
|
87
|
-
*
|
|
88
|
-
* @param state - The state object this render pass holds (the useHookState value, before the render derives the re-placed value) / この描画が持つステートのオブジェクト (描画が収め直した値を導く前の useHookState の値)
|
|
89
|
-
* @returns Nothing / なし
|
|
90
|
-
*/
|
|
91
|
-
forgetHandedUnless(state: T): void
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** Marks a mirror that holds no record of a hand-off / 受け渡しの記録を持たない印 */
|
|
95
|
-
const NOTHING_HANDED: unique symbol = Symbol("nothing handed")
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* A ref-shaped holder that counts the writes made through `current`, so a commit can tell whether a returned function wrote after the committing render ran, and that keeps the record of the object a returned function last handed to the state it mirrors.
|
|
99
|
-
* `current` を通した書き込みを数え、確定する描画が走った後に返す関数が書いたかを確定の段階で判定でき、返す関数が写すステートへ最後に渡したオブジェクトを記録する、ref の形の入れ物。
|
|
14
|
+
* A ref-shaped holder that counts the writes made through `current`, so a commit can tell whether a function wrote after the committing render ran.
|
|
15
|
+
* `current` を通した書き込みを数え、確定する描画が走った後に関数が書いたかを確定の段階で判定できる、ref の形の入れ物。
|
|
100
16
|
*/
|
|
101
|
-
class CommittedMirror<T> implements
|
|
17
|
+
export class CommittedMirror<T> implements React.RefObject<T> {
|
|
102
18
|
/** Held value / 保持する値 */
|
|
103
19
|
private held: T
|
|
104
20
|
|
|
105
21
|
/** Writes made through `current` so far / これまでに `current` を通して書かれた回数 */
|
|
106
22
|
private writeCount = 0
|
|
107
23
|
|
|
108
|
-
/** The object a returned function last handed to the mirrored state, while it can still be the state's last queued update / 返す関数が写すステートへ最後に渡したオブジェクト (それがステートの最後に積んだ更新であり得る間) */
|
|
109
|
-
private handed: T | typeof NOTHING_HANDED = NOTHING_HANDED
|
|
110
|
-
|
|
111
24
|
/**
|
|
112
25
|
* Creates the holder with the first render's value.
|
|
113
26
|
* 最初の描画の値で入れ物を作るコンストラクタ。
|
|
@@ -119,8 +32,8 @@ class CommittedMirror<T> implements CommittedRef<T> {
|
|
|
119
32
|
}
|
|
120
33
|
|
|
121
34
|
/**
|
|
122
|
-
* The value of the last committed render, or a later value
|
|
123
|
-
*
|
|
35
|
+
* The value of the last committed render, or a later value written outside render.
|
|
36
|
+
* 最後に確定した描画の値、またはその後に描画の外で書かれた値。
|
|
124
37
|
*
|
|
125
38
|
* @returns The held value / 保持する値
|
|
126
39
|
*/
|
|
@@ -129,8 +42,8 @@ class CommittedMirror<T> implements CommittedRef<T> {
|
|
|
129
42
|
}
|
|
130
43
|
|
|
131
44
|
/**
|
|
132
|
-
* Records a value
|
|
133
|
-
*
|
|
45
|
+
* Records a value written outside render: by an event handler, an effect or an effect's cleanup.
|
|
46
|
+
* 描画の外 (事象の処理・副作用とその後始末) で書かれた値の記録。
|
|
134
47
|
*
|
|
135
48
|
* @param next - The written value / 書かれた値
|
|
136
49
|
*/
|
|
@@ -150,51 +63,8 @@ class CommittedMirror<T> implements CommittedRef<T> {
|
|
|
150
63
|
}
|
|
151
64
|
|
|
152
65
|
/**
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
* @param value - The object about to be handed over / これから渡すオブジェクト
|
|
157
|
-
* @returns Nothing / なし
|
|
158
|
-
*/
|
|
159
|
-
hand(value: T): void {
|
|
160
|
-
this.handed = value
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Whether the held value is the recorded object.
|
|
165
|
-
* 保持する値が記録したオブジェクトか。
|
|
166
|
-
*
|
|
167
|
-
* @returns True when a record exists and names the held object / 記録があり、保持するオブジェクトを指していれば true
|
|
168
|
-
*/
|
|
169
|
-
get holdsHanded(): boolean {
|
|
170
|
-
return this.handed === this.held
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Drops the record (see CommittedRef.forgetHanded).
|
|
175
|
-
* 記録を消す関数 (CommittedRef.forgetHanded を参照)。
|
|
176
|
-
*
|
|
177
|
-
* @returns Nothing / なし
|
|
178
|
-
*/
|
|
179
|
-
forgetHanded(): void {
|
|
180
|
-
this.handed = NOTHING_HANDED
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Drops the record unless it is the state object the running render pass holds (see CommittedRef.forgetHandedUnless).
|
|
185
|
-
* 記録が、いま走っている描画の持つステートのオブジェクトでなければ記録を消す関数 (CommittedRef.forgetHandedUnless を参照)。
|
|
186
|
-
*
|
|
187
|
-
* @param state - The state object this render pass holds / この描画が持つステートのオブジェクト
|
|
188
|
-
* @returns Nothing / なし
|
|
189
|
-
*/
|
|
190
|
-
forgetHandedUnless(state: T): void {
|
|
191
|
-
// 消すだけの書き込みに限る。確定しない描画が記録を書けば、キューに無い値を最後の更新と見なして受け渡しを省いてしまう
|
|
192
|
-
if (this.handed !== state) this.handed = NOTHING_HANDED
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Copies a committed render's value unless a returned function wrote after that render ran.
|
|
197
|
-
* 確定した描画の値の写し (その描画が走った後に返す関数が書いていれば写さない)。
|
|
66
|
+
* Copies a committed render's value unless a write came after that render ran.
|
|
67
|
+
* 確定した描画の値の写し (その描画が走った後に書き込みがあれば写さない)。
|
|
198
68
|
*
|
|
199
69
|
* @param committed - The committed render's value / 確定した描画の値
|
|
200
70
|
* @param writesAtRender - `writes` as that render read it / その描画が読んだ `writes`
|
|
@@ -206,34 +76,31 @@ class CommittedMirror<T> implements CommittedRef<T> {
|
|
|
206
76
|
}
|
|
207
77
|
|
|
208
78
|
/**
|
|
209
|
-
* Mirrors
|
|
210
|
-
*
|
|
79
|
+
* Mirrors the value of each committed render into a holder that functions outliving their render read at event time: the one commit-copy rule that useCommittedRef and the hooks' state mirrors (useStateMirror in renderScope.ts) share.
|
|
80
|
+
* 確定した描画の値を、描画より長く生きる関数が事象の時点で読む入れ物へ写すフック (useCommittedRef とフックのステートの写し (renderScope.ts の useStateMirror) が共有する、ただ 1 つの写しの規則)。
|
|
211
81
|
*
|
|
212
82
|
* React runs a component body for renders it discards or leaves suspended (a transition waiting on Suspense, an
|
|
213
83
|
* interrupted concurrent render), so the copy is made in the commit phase, as an insertion effect: React runs it before
|
|
214
84
|
* every layout effect of the commit and also for commits inside a hidden Activity, so a descendant's layout effect and a
|
|
215
|
-
* hidden tree read the commit they belong to. The returned functions
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
* body clears with CommittedRef.forgetHandedUnless right after this call, and the hook's record of its own re-placement
|
|
222
|
-
* with CommittedRef.forgetHanded.
|
|
85
|
+
* hidden tree read the commit they belong to. The returned functions, and a component's own functions, may write the
|
|
86
|
+
* holder from any code outside render: an event handler, an effect or an effect's cleanup (a setter records the value
|
|
87
|
+
* it handed to the state). A commit copies its render's value only when no such write happened after that render ran,
|
|
88
|
+
* because a time-sliced render can run before a write and commit after it with an older value. The holder keeps its
|
|
89
|
+
* identity for the life of the component, so a function that reads it keeps its own. While a render is in progress the
|
|
90
|
+
* holder still holds the last committed value, not the value of that render.
|
|
223
91
|
* React は捨てる描画や中断したままの描画 (Suspense を待つ移行、割り込まれた並行描画) でも本体を走らせるため、写しは確定の段階で
|
|
224
92
|
* 挿入副作用として行う (確定のどのレイアウト副作用よりも前に、隠れた Activity の中の確定でも走る。子孫のレイアウト副作用も隠れた木も、
|
|
225
|
-
* 自分が属する確定の値を読む)
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* (CommittedRef.hand / holdsHanded)、フック本体はこの呼び出しの直後に CommittedRef.forgetHandedUnless で、フック自身の収め直しの記録は
|
|
230
|
-
* CommittedRef.forgetHanded でそれを消す。
|
|
93
|
+
* 自分が属する確定の値を読む)。返す関数とコンポーネント自身の関数は、描画の外のどこからでも入れ物へ書いてよく (事象の処理・副作用と
|
|
94
|
+
* その後始末。設定関数はステートへ渡した値を記録する)、確定はその描画が走った後に書き込みが無かったときだけ、その描画の値を写す
|
|
95
|
+
* (時間分割した描画は書き込みの前に走って書き込みの後に確定することがあり、その値は書き込みより古い)。入れ物は
|
|
96
|
+
* コンポーネントの存続中ずっと同じで、それを読む関数の同一性も保たれる。描画の途中の入れ物は、その描画の値ではなく最後に確定した値を持つ。
|
|
231
97
|
*
|
|
232
98
|
* @param value - The value this render holds / この描画が持つ値
|
|
233
|
-
* @
|
|
99
|
+
* @param create - Creates the holder with the first render's value / 最初の描画の値で入れ物を作る関数
|
|
100
|
+
* @returns The holder created on the first render, holding the value of the last committed render (the first render's value until the first commit), or a later value written outside render / 最初の描画で作った入れ物 (最後に確定した描画の値 (最初の確定までは最初の描画の値)、またはその後に描画の外で書かれた値を持つ)
|
|
234
101
|
*/
|
|
235
|
-
export function
|
|
236
|
-
const [mirror] = useState(() =>
|
|
102
|
+
export function useCommittedHolder<T, M extends CommittedMirror<T>>(value: T, create: (initial: T) => M): M {
|
|
103
|
+
const [mirror] = useState(() => create(value))
|
|
237
104
|
// 書き込みの回数は描画の時点で読む。確定の時点で読むと、この描画が譲っていた間に返す関数が書いた値を、この描画の古い値で上書きする
|
|
238
105
|
const writesAtRender = mirror.writes
|
|
239
106
|
// 依存配列は置かない。値が同じ確定でも写し直さないと、確定しなかった更新 (中断した移行の中で呼んだ設定関数) が書いた値が残る
|
|
@@ -242,3 +109,24 @@ export function useCommittedRef<T>(value: T): CommittedRef<T> {
|
|
|
242
109
|
})
|
|
243
110
|
return mirror
|
|
244
111
|
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Mirrors a value of the committed render into a ref that the functions a hook returns, or a component's own functions that outlive their render, read at event time.
|
|
115
|
+
* 確定した描画の値を、フックの返す関数やコンポーネントの描画より長く生きる自分の関数が事象の時点で読む ref へ写すフック。
|
|
116
|
+
*
|
|
117
|
+
* The copy follows useCommittedHolder: it is made from the commit, before any layout effect of that commit, and a write
|
|
118
|
+
* made outside render after the committing render ran is not overwritten. A state hook mirrors the states its returned
|
|
119
|
+
* functions hand values to with useStateMirror (renderScope.ts), whose render scope also keeps the hand-off records and
|
|
120
|
+
* confines a call made inside the hook's duringRender(action) to the render in progress; this ref serves the values
|
|
121
|
+
* nothing writes during a render (bounds, candidates, callbacks, selector-arrow destinations) and a component's own flags.
|
|
122
|
+
* 写しは useCommittedHolder に従う (確定から、その確定のどのレイアウト副作用よりも前に写し、確定する描画が走った後に描画の外で書いた値は上書きしない)。
|
|
123
|
+
* 状態フックは、返す関数が値を渡すステートを useStateMirror (renderScope.ts) で写す (その描画の範囲が受け渡しの記録も持ち、フックの
|
|
124
|
+
* duringRender(action) の中の呼び出しを進行中の描画に閉じ込める)。この ref は、描画中に誰も書かない値 (境界・候補・コールバック・◀▶ の行き先) と
|
|
125
|
+
* コンポーネント自身の旗を運ぶ。
|
|
126
|
+
*
|
|
127
|
+
* @param value - The value this render holds / この描画が持つ値
|
|
128
|
+
* @returns A ref holding the value of the last committed render (the first render's value until the first commit), or a later value written outside render / 最後に確定した描画の値 (最初の確定までは最初の描画の値)、またはその後に描画の外で書かれた値を持つ ref
|
|
129
|
+
*/
|
|
130
|
+
export function useCommittedRef<T>(value: T): React.RefObject<T> {
|
|
131
|
+
return useCommittedHolder(value, (initial) => new CommittedMirror(initial))
|
|
132
|
+
}
|