Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove Loadable, optional onLoads #1333

Merged
merged 17 commits into from
Jan 24, 2022

Conversation

st-pasha
Copy link
Contributor

@st-pasha st-pasha commented Jan 22, 2022

Description

  1. Game no longer depends on Loadable, that is, when creating a new Game subclass you only need to say class MyGame with Game instead of class MyGame with Loadable, Game. This is done by moving the 2 lines of code that are inside Loadable into the Game class. The benefit here is that it simplifies the usage of the Game class.

  2. Component no longer depends on Loadable. This brings in several advantages:

    • Conceptually, Component is the most "base" class in the Flame engine. Having it being derived from some other helper class is not ideal.
    • The onLoad method is now defined within the Component class, alongside all other lifecycle methods, which makes it easier to document.
    • The onLoadCache variable is removed -- the fact that the component is loaded only once is guarded by the isLoaded flag, so carrying around that Future was unnecessary and was only increasing the size of the Component object.
  3. Loadable mixin is now empty and declared Deprecated, to be removed in 1.2.0. Anyone who uses a custom Game class via with Loadable, Game can simply remove Loadable from the declaration.

  4. The default onLoad methods are no longer declared as @mustCallSuper, since they have no functionality. This simplifies user code: there is no longer need to say await super.onLoad() at the start of your onLoad() implementation. A derived class can always re-add this annotation if it overrides onLoad and if it intends to be derived further.

Checklist

  • The title of my PR starts with a Conventional Commit prefix (fix:, feat:, docs: etc).
  • I have read the Contributor Guide and followed the process outlined for submitting PRs.
  • (NA) I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • (NA) I have updated/added relevant examples in examples.

Breaking Change

  • No, this is not a breaking change.

@wolfenrain
Copy link
Contributor

wolfenrain commented Jan 23, 2022

We could remove the breaking change by having an empty Loadable mixin right? And then just deprecated it for the next breaking release?

@st-pasha
Copy link
Contributor Author

We could remove the breaking change by having an empty Loadable mixin right? And then just deprecated it for the next breaking release?

Yeah, makes sense, let's do that.

@st-pasha st-pasha changed the title refactor!: Remove Loadable, optional onLoads refactor: Remove Loadable, optional onLoads Jan 23, 2022
Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

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

Lgtm! Don't remember why I created that mixin from the beginning, but this is clearly nicer.

@spydon spydon merged commit 05f7a4c into flame-engine:main Jan 24, 2022
@st-pasha st-pasha deleted the ps/loadable branch January 24, 2022 23:01
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.

4 participants