Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Feb 11, 2026

Link issues

fixes #7640

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add a resettable FlipClock initialization flow and expose it via a new instance Reset API.

New Features:

  • Expose a public Reset method on FlipClock to reinitialize the clock from the configured start value.

Enhancements:

  • Refactor FlipClock JavaScript initialization to accept an invocation handler and track timing state on the options object, supporting reuse when resetting.

Copilot AI review requested due to automatic review settings February 11, 2026 07:22
@bb-auto bb-auto bot added the enhancement New feature or request label Feb 11, 2026
@bb-auto bb-auto bot added this to the v10.3.0 milestone Feb 11, 2026
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 11, 2026

Reviewer's Guide

Adds a reusable Reset method to FlipClock and refactors the JavaScript initialization logic to make the countdown/counter state part of the options object, updating invocation wiring between .NET and JS accordingly.

Sequence diagram for FlipClock Reset and JS init interaction

sequenceDiagram
    actor User
    participant FlipClock
    participant JSInterop
    participant FlipClock_js
    participant Browser

    User->>FlipClock: Reset()
    activate FlipClock
    FlipClock->>JSInterop: InvokeVoidAsync init(Id, Interop, options)
    activate JSInterop
    JSInterop->>FlipClock_js: init(id, invoke, options)
    deactivate JSInterop
    activate FlipClock_js
    FlipClock_js->>Browser: requestAnimationFrame(flip)
    activate Browser
    loop every_1000ms
        Browser->>FlipClock_js: flip(timestamp)
        FlipClock_js->>FlipClock_js: go(el, options)
        FlipClock_js->>FlipClock_js: getDate(options)
        FlipClock_js->>FlipClock_js: getConfig(el)
        FlipClock_js->>FlipClock_js: setDigits(list, value, digits, options.countDown)
        alt countdown_completed
            FlipClock_js->>JSInterop: invoke.invokeMethodAsync(OnCompleted)
            deactivate FlipClock_js
            JSInterop->>FlipClock: OnCompleted()
            deactivate Browser
        else not_completed
            Browser-->>Browser: schedule next frame
        end
    end
    deactivate FlipClock
Loading

Class diagram for updated FlipClock component

classDiagram
    class FlipClock {
        +Task InvokeInitAsync()
        +Task Reset()
        -double GetTicks()
        +Task OnCompleted()
    }
Loading

File-Level Changes

Change Details Files
Expose a Reset instance method on FlipClock that re-initializes the JS flip clock with the current configuration and use it for initial component initialization.
  • Change InvokeInitAsync override to call the new Reset method instead of invoking JS directly
  • Implement public Reset method that calls JS init with Id, Interop instance, view mode, start value, and completion callback name
src/BootstrapBlazor/Components/FlipClock/FlipClock.razor.cs
Refactor FlipClock JavaScript initialization to accept a separate .NET invoke object, track counter/countdown state inside options, and extract reusable helpers for computing time and updating digits.
  • Change init signature to accept (id, invoke, options) and extend default options with counter, totalMilliseconds, and countDown fields
  • Move go, getDate, getConfig, and setDigits into standalone helper functions that operate on el and the shared options object
  • Update the countdown completion path to use the separate invoke argument instead of options.invoke, and to rely on options.countDown state
src/BootstrapBlazor/Components/FlipClock/FlipClock.razor.js

Assessment against linked issues

Issue Objective Addressed Explanation
#7640 Add a public Reset instance method to the FlipClock component that can be called to restart the clock/countdown.
#7640 Ensure that calling Reset reinitializes the underlying JavaScript FlipClock state (including countdown state) so that timing restarts from the configured start value.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ArgoZhang ArgoZhang merged commit bec6064 into main Feb 11, 2026
9 checks passed
@ArgoZhang ArgoZhang deleted the feat-flip branch February 11, 2026 07:23
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Calling the new Reset method will invoke init again and schedule a new requestAnimationFrame loop without cancelling the previous one; consider tracking and cancelling the existing animation frame (e.g., storing the id and using cancelAnimationFrame) to avoid multiple overlapping update loops per clock instance.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Calling the new `Reset` method will invoke `init` again and schedule a new `requestAnimationFrame` loop without cancelling the previous one; consider tracking and cancelling the existing animation frame (e.g., storing the id and using `cancelAnimationFrame`) to avoid multiple overlapping update loops per clock instance.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (aebb38d) to head (8678263).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7657   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          750       750           
  Lines        33185     33191    +6     
  Branches      4605      4605           
=========================================
+ Hits         33185     33191    +6     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new instance-level reset capability to the FlipClock component so consumers can restart counting (especially after a countdown completes), aligning with issue #7640’s requested behavior.

Changes:

  • Introduces a new public Reset() method on FlipClock and uses it for initial JS initialization.
  • Refactors FlipClock.razor.js to move timing state into the options object and changes JS init signature to accept a separate .NET interop reference.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/BootstrapBlazor/Components/FlipClock/FlipClock.razor.js Updates init signature/state handling and refactors tick/render helpers.
src/BootstrapBlazor/Components/FlipClock/FlipClock.razor.cs Adds Reset() API and routes initial initialization through it.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 21 to 39
@@ -104,6 +39,72 @@
requestAnimationFrame(flip);
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init() starts a new requestAnimationFrame loop every time it’s called, but there’s no cancellation/guard for an existing loop on the same element. With the new Reset() API (which re-invokes init), repeated resets will leave prior loops running concurrently (double updates + potential multiple onCompleted invocations). Consider tracking the RAF handle/token per id (e.g., in a module-level map or on the element) and cancel/stop the previous loop before starting a new one; also consider exporting a dispose(id) to stop the loop when the component is removed.

Copilot uses AI. Check for mistakes.

if (countDown && current.hours === 0 && current.minutes === 0 && current.seconds === 0) {
options.invoke.invokeMethodAsync(options.onCompleted);
if (options.countDown && current.hours === 0 && current.minutes === 0 && current.seconds === 0) {
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Countdown completion detection should not rely only on hours/minutes/seconds == 0. For durations >= 24h, when totalMilliseconds lands exactly on a day boundary (e.g., 86400000ms), hours/minutes/seconds become 0 while days is still > 0, causing premature completion. Use options.totalMilliseconds <= 0 (or include days/months/years in the check) to decide completion reliably.

Suggested change
if (options.countDown && current.hours === 0 && current.minutes === 0 && current.seconds === 0) {
if (options.countDown && options.totalMilliseconds <= 0) {

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +9
counter: 0,
totalMilliseconds : 0,
countDown: false
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totalMilliseconds : 0 has inconsistent spacing before the colon compared to typical object literal formatting in this file (startValue: 0, onCompleted: null). Consider normalizing to totalMilliseconds: 0 for consistency.

Copilot uses AI. Check for mistakes.
/// <para lang="zh">重置方法</para>
/// <para lang="en">Reset method</para>
/// </summary>
/// <returns></returns>
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XML doc has an empty <returns> tag on a new public API (Reset). Please either remove the tag or fill it with the standard Task description (e.g., “A Task representing the asynchronous operation.”) to match other public methods’ docs.

Suggested change
/// <returns></returns>
/// <returns>A Task representing the asynchronous operation.</returns>

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(FlipClock): add Reset instance method

1 participant