Skip to content

Commit d8cbb85

Browse files
committed
fix: Address second round of code review findings
- Remove redundant null-check before clearTimeout in Debounce_TS.ipynb (clearTimeout is null-safe per spec) - Add SVG accessibility: role='img' and aria-label on React visualization - Remove unused SVG marker definitions (arrowVis, reactArrowGreen, reactArrowRed) that had zero references in the component - Fix remaining t=0 misleading text in README.md 基底条件 section - Add expected output to Python example for completeness - Fix stale 'Production with SRI' comment in README_react.html
1 parent 88b2156 commit d8cbb85

3 files changed

Lines changed: 13 additions & 46 deletions

File tree

JavaScript/2627. Debounce/Claude Code Sonnet 4.5 extended/Debounce_TS.ipynb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,8 @@
8989
" let timeoutId: ReturnType<typeof setTimeout> | null = null;\n",
9090
" \n",
9191
" return function(...args: number[]): void {\n",
92-
" // 既存のタイマーがあればキャンセル\n",
93-
" if (timeoutId !== null) {\n",
94-
" clearTimeout(timeoutId);\n",
95-
" }\n",
92+
" // 既存のタイマーをキャンセル(clearTimeoutはnull安全)\n",
93+
" clearTimeout(timeoutId);\n",
9694
" \n",
9795
" // 新しいタイマーをセット(t ミリ秒後に fn を実行)\n",
9896
" timeoutId = setTimeout(() => {\n",
@@ -127,7 +125,7 @@
127125
"\n",
128126
"1. **タイマー管理**\n",
129127
" - `timeoutId`変数で現在のタイマーを追跡\n",
130-
" - `null`チェックで型安全性を確保\n",
128+
" - `clearTimeout`はnull/undefinedを安全に受け付ける\n",
131129
"\n",
132130
"2. **キャンセルメカニズム**\n",
133131
" - 新しい呼び出し時に既存タイマーを`clearTimeout`でクリア\n",
@@ -143,8 +141,8 @@
143141
"// ✅ 型安全な実装\n",
144142
"let timeoutId: ReturnType<typeof setTimeout> | null = null;\n",
145143
"// - ReturnType: setTimeoutの戻り値型を自動推論\n",
146-
"// - | null: 初期状態とクリア後の状態を表現\n",
147-
"// - strict null checkで安全性確保\n",
144+
"// - | null: 初期状態を表現\n",
145+
"// - clearTimeout(null)は仕様上安全(no-op)\n",
148146
"\n",
149147
"// ✅ 引数の型保持\n",
150148
"return function(...args: number[]): void {\n",
@@ -174,7 +172,7 @@
174172
"### 型安全性の活用\n",
175173
"\n",
176174
"1. **コンパイル時エラー防止**\n",
177-
" - `timeoutId`の`null`チェックで未初期化エラーを防止\n",
175+
" - `timeoutId`の型で未初期化状態を安全に管理\n",
178176
" - strict modeでのnull安全性確保\n",
179177
"\n",
180178
"2. **型推論による開発効率**\n",

JavaScript/2627. Debounce/Claude Code Sonnet 4.5 extended/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ graph LR
102102

103103
### 基底条件
104104

105-
- `t = 0` の場合: 即座に実行(実質的にデバウンスなし)
105+
- `t = 0` の場合: `Timer(0, fn, ...)` でスレッドが起動されるため完全に即座ではなく、連続呼び出しではレースの可能性がある
106106
- 引数なしの場合: 空の `*args, **kwargs` で正常動作
107107

108108
### 終了性
@@ -241,9 +241,9 @@ if __name__ == "__main__":
241241
# 2が125ms(75 + 50)に実行される
242242
time.sleep(0.1) # 待機してタイマーを発火させる
243243

244-
# タイマースレッドが実行を完了するのを待つ
245-
# 注: threading.Timerはデーモンスレッドではないため、
246-
# メインスレッド終了後も実行される
244+
# 期待出力(タイムスタンプは実行環境依存):
245+
# [xxx.xxx] Called with: (2,)
246+
# → dlog(1)はキャンセルされ、dlog(2)のみが実行される
247247
```
248248

249249
### 主要ステップの説明

JavaScript/2627. Debounce/Claude Code Sonnet 4.5 extended/README_react.html

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ <h3 class="text-xl font-bold text-teal-800 mb-3">実装比較</h3>
776776
</footer>
777777
</div>
778778

779-
<!-- React & ReactDOM (Production with SRI) -->
779+
<!-- React & ReactDOM (Production) -->
780780
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
781781
<script
782782
crossorigin
@@ -914,40 +914,9 @@ <h3 class="text-xl font-bold text-teal-800 mb-3">実装比較</h3>
914914
<svg
915915
viewBox="0 0 700 350"
916916
style={{ maxWidth: '100%', height: 'auto', marginTop: '20px' }}
917+
role="img"
918+
aria-label="デバウンス動作のタイムライン可視化"
917919
>
918-
<defs>
919-
<marker
920-
id="arrowVis"
921-
markerWidth="8"
922-
markerHeight="8"
923-
refX="7"
924-
refY="3"
925-
orient="auto"
926-
>
927-
<path d="M0,0 L0,6 L7,3 z" fill="#64748b" />
928-
</marker>
929-
<marker
930-
id="reactArrowGreen"
931-
markerWidth="8"
932-
markerHeight="8"
933-
refX="7"
934-
refY="3"
935-
orient="auto"
936-
>
937-
<path d="M0,0 L0,6 L7,3 z" fill="#059669" />
938-
</marker>
939-
<marker
940-
id="reactArrowRed"
941-
markerWidth="8"
942-
markerHeight="8"
943-
refX="7"
944-
refY="3"
945-
orient="auto"
946-
>
947-
<path d="M0,0 L0,6 L7,3 z" fill="#dc2626" />
948-
</marker>
949-
</defs>
950-
951920
{/* タイムライン */}
952921
<line
953922
x1="50"

0 commit comments

Comments
 (0)