fix(dealer): reset countdown state when its placeholder leaves the display - #959
Merged
Conversation
…splay Display kept one start timestamp per countdown id and never dropped it, so a reused id resolved against the previous attempt's elapsed time and rendered a remaining value of 0 forever. Every id that repeats hit this: beholder's `openPage_<url>` on a navigation retry, and deal()'s per-lane `<index>_interval` from the second item onward. The map also grew one entry per unique id and was never trimmed for the whole run. Drop the ids that are no longer on the display stack whenever the stack is rebuilt, so a returning id counts down from its full duration again. Verbose mode has no repainted frame — each line is final at the moment it is written — so it renders the full duration and keeps no state at all.
Display is not re-exported from the package entry and `exports` only exposes `.`, so it cannot be reached from outside the package. Only Lanes can be used directly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
Lanesの%countdown(満了時間, ID, 単位)%プレースホルダが、同じ ID が再登場した瞬間から残り 0 に張り付く問題を修正する。Displayはカウントダウン ID ごとの開始時刻をMapに記録するが、一度書き込んだエントリを削除する経路が存在しなかった。そのため同じ ID が2回目以降に描画されると前回の開始時刻を引き継ぎ、経過時間がすでに満了時間を超えているためMath.max(time - elapsed, 0)が常に0を返していた。同時に、この
Mapは実行中いちども縮まないため、ユニークな ID の数だけエントリが積み上がっていた。影響していた箇所
ID を再利用する呼び出しはすべて該当する。
@d-zero/beholderscraper.tsopenPage_<url>@d-zero/dealerdeal.ts<index>_interval変更内容
Display.#dropStaleCountDowns()(新規)表示スタックが作り直されるたびに、スタック上に存在しないカウントダウン ID の開始時刻を破棄する。ID が再登場すると満了時間から数え直され、
Mapも画面に出ている ID だけを保持する。フレーム描画時ではなくスタック更新時に判定している。フレーム間隔(既定 33ms)より短い間に「消えて再登場」する ID を取りこぼさないため —
deal()のlanes.delete(index)→ 次アイテムのupdate()がまさにこの並びになる。Displayの利用者はLanesのみで、Lanes.write()は毎回#logs全件とヘッダーを送るため、判定対象は常に画面全体となる。verbose モード
verbose には再描画されるフレームが存在せず、1行は出力された瞬間に確定する。カウントダウン行が出るのは待機の開始時点なので、残り時間を追跡せず常に満了時間を出力するようにした(従来はここでも2回目以降が 0 に潰れていた)。
ドキュメント
Lanes.update()の JSDoc に%countdown()の構文・ID の寿命・verbose 時の挙動・@exampleを追加(従来まったく文書化されていなかった)using」の注記からDisplayを除去。Displayはindex.tsから再エクスポートされておらずexportsも.のみのため、パッケージ外からは到達できないテスト
display.spec.tsに 7 件、lanes.spec.tsに 2 件追加。s単位の丸めLanes経由: レーン番号だけを ID にした待機が次のアイテムで数え直しになる / 別レーンの ID を巻き込まない新規の本番コードは「消すとテストが落ちる」ことを実測で確認済み(
#dropStaleCountDowns()の呼び出しを外すと 5 件、verbose 分岐を潰すと 1 件が失敗する)。フレームの取得には
Writableのresizeを発火させて任意のフェイククロック時刻で1フレーム描画させている。fps タイマーの間隔(1000/30 等)は整数に割り切れず、期待値をハードコードできないため。互換性
公開シグネチャと
exportsは無変更。意図された挙動へのバグ修正のため patch 相当。利用側(
@d-zero/beholder/@nitpicker/*等)はコード変更不要で、@d-zero/dealerを上げるだけで表示が直る。