Skip to content

refactor: inline AppBase tick as a class-field arrow#8639

Merged
willeastcott merged 4 commits intomainfrom
refactor/inline-tick-as-class-field
Apr 23, 2026
Merged

refactor: inline AppBase tick as a class-field arrow#8639
willeastcott merged 4 commits intomainfrom
refactor/inline-tick-as-class-field

Conversation

@willeastcott
Copy link
Copy Markdown
Contributor

@willeastcott willeastcott commented Apr 22, 2026

Summary

  • Replaces the module-level makeTick closure factory in AppBase with a class-field arrow function tick, removing the no-use-before-define workaround and the const application = _app alias.
  • Deletes the now-unused @callback MakeTickCallback JSDoc typedef.
  • Drops the this.tick = makeTick(this) assignment (and its comment) from init().

Rationale

The old pattern was a forward-declared module-scope factory called from init(), which required an ESLint disable comment on every tick of development and obscured this behind a captured application alias. A class-field arrow is:

  • idiomatic (matches the many other AppBase class fields),
  • auto-bound, so this.tick can still be passed straight to requestAnimationFrame,
  • initialised in the base constructor, making this.tick available to subclass constructor bodies.

Public API

  • No public API changes. tick is @ignore (internal), and remains a writable instance property, so subclasses like the editor's ViewportApplication can continue to reassign it after super().

Test plan

  • npx eslint src/framework/app-base.js — clean.
  • Run an engine example and confirm the main loop ticks normally and stats update.
  • Run an XR example and confirm the XR frame loop still drives updates.

Replace the module-level `makeTick` closure factory with a class-field
arrow function `tick` on AppBase. Removes the `no-use-before-define`
workaround in `init()`, the `const application = _app` alias, and the
now-unused `MakeTickCallback` typedef.

No behaviour change: `tick` remains a writable instance property, so
subclasses (e.g. the editor's ViewportApplication) can still reassign it
after `super()`.

Made-with: Cursor
The assignment was a pair to the old `this.tick = makeTick(this)` in
init(). Now that `tick` is a permanent class-field arrow, nulling it is
both asymmetric with how it is created and a type error against its
declared signature. The arrow's own `if (!this.graphicsDevice) return;`
guard already provides graceful no-op behaviour post-destroy, and the
in-flight rAF is cancelled by `AppBase.cancelTick(this)`.

Made-with: Cursor
Copy link
Copy Markdown
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

Refactors AppBase’s main loop scheduling by replacing the module-scope makeTick closure factory with an auto-bound class-field arrow function tick, simplifying initialization and linting while keeping tick as an internal, writable instance property.

Changes:

  • Introduces tick = (timestamp, xrFrame) => { ... } as a class-field arrow function on AppBase.
  • Removes the makeTick factory and its associated @callback MakeTickCallback typedef.
  • Removes the this.tick = makeTick(this) assignment from init().

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

Comment thread src/framework/app-base.js
Comment thread src/framework/app-base.js
@mvaligursky
Copy link
Copy Markdown
Contributor

Is this a breaking change?
MakeTickCallback was public API I think.

@willeastcott
Copy link
Copy Markdown
Contributor Author

Is this a breaking change? MakeTickCallback was public API I think.

I mean, technically, yes because that symbol is now gone from the API reference. But who would be using that?

@mvaligursky
Copy link
Copy Markdown
Contributor

perhaps leave the old function, and add Debug.removed to it in case somebody used it.

@willeastcott
Copy link
Copy Markdown
Contributor Author

perhaps leave the old function, and add Debug.removed to it in case somebody used it.

It's not a function. It's a callback type. But I honestly can't think of how it can be used by users. I think it leaked by mistake.

@willeastcott willeastcott self-assigned this Apr 23, 2026
@willeastcott willeastcott added the enhancement Request for a new feature label Apr 23, 2026
@willeastcott willeastcott merged commit a77aa47 into main Apr 23, 2026
8 checks passed
@willeastcott willeastcott deleted the refactor/inline-tick-as-class-field branch April 23, 2026 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Request for a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants