Skip to content

feat!: Make Timer and TimerComponent APIs consistent - #4076

Merged
spydon merged 1 commit into
mainfrom
devkage/timer-api-consistency
Sep 30, 2026
Merged

spydon merged 1 commit into
mainfrom
devkage/timer-api-consistency

Conversation

@ufrshubham

@ufrshubham ufrshubham commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Description

Makes the Timer and TimerComponent APIs consistent.

Previously TimerComponent took a named period, while Timer took a positional limit. Also, TimerComponent exposed a public onTick method that wrapped the user callback, which could go out of sync with Timer.onTick.

Changes:

  • Timer now takes a required named period (was positional limit), and the Timer.limit field is renamed to Timer.period.
  • TimerComponent.onTick() is removed. The callback passed to the constructor is set directly on the internal timer, and tickWhenLoaded calls timer.onTick.
  • Updated SpawnComponent, HasBehaviorTree, docs, examples and tests accordingly.

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Migration instructions

If the PR is breaking, uncomment this header and add instructions for how to migrate from the
currently released version in-between the two following tags:

Before:

final timer = Timer(1, repeat: true, onTick: tick);
timer.limit = 2;

class MyTimer extends TimerComponent {
  MyTimer() : super(period: 1, repeat: true);

  @override
  void onTick() => tick();
}

After:

final timer = Timer(period: 1, repeat: true, onTick: tick);
timer.period = 2;

class MyTimer extends TimerComponent {
  MyTimer() : super(period: 1, repeat: true) {
    timer.onTick = tick;
  }
}

Related Issues

Closes #2386

Timer now takes a required named `period` (renamed from the positional
`limit`), matching TimerComponent. TimerComponent.onTick is removed and
the provided callback is set directly on the internal Timer.

Fixes #2386

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@spydon spydon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lgtm, why did we build it that inconsistent to begin with... 😆

@ufrshubham ufrshubham changed the title feat!: Make Timer and TimerComponent APIs consistent feat!: Make Timer and TimerComponent APIs consistent Sep 30, 2026
@spydon
spydon merged commit 87a0265 into main Sep 30, 2026
11 checks passed
@spydon
spydon deleted the devkage/timer-api-consistency branch September 30, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Timer and TimerComponent APIs are inconsistent

2 participants