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: Loadable mixin no longer declares onMount and onRemove #1243

Merged
merged 11 commits into from
Dec 27, 2021

Conversation

st-pasha
Copy link
Contributor

Description

Loadable mixin is currently used for 2 classes: Game and Component. Its purpose is to provide the caching layer for the future returned by the onLoad() method. Having empty methods onMount() / onRemove() in that mixin does not fit its overall purpose. (Plus, in general, the purpose of any mixin is to add some additional concrete functionality into an existing class).

In addition to the scope mismatch, these methods perform similar yet not quite the same function in Game and Component. Having these methods declared directly within Game and Component allows to document them more precisely, and help the user understand their functionality/purpose better.

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.
  • 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.

Breaking Change

  • No, this is not a breaking change.

Related Issues

Closes #1210

@st-pasha
Copy link
Contributor Author

Note: I wasn't quite able to figure out the difference between onMount and onAttach for the Game class -- which I guess only stresses the need for clear and precise documentation for that function.

@spydon
Copy link
Member

spydon commented Dec 18, 2021

Note: I wasn't quite able to figure out the difference between onMount and onAttach for the Game class -- which I guess only stresses the need for clear and precise documentation for that function.

onAttach is when the Flutter widget is attached to the Flutter widget tree, onMount is when the component is added to a component tree (after onLoad).

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

@st-pasha
Copy link
Contributor Author

onAttach is when the Flutter widget is attached to the Flutter widget tree, onMount is when the component is added to a component tree (after onLoad).

Exactly: this is where it gets confusing. I understand onMount for the Component class. But the Game class is a different story. So the question is: what is onMount in the Game class, and how is it different from the onAttach handler?

The situation with onRemove / onDetach is similar, only I believe the former is called before the game is removed from the widget, while the latter called after. We should consider at some point to rename them to improve clarity. For example: onBeforeDetach / onAfterDetach.

@spydon
Copy link
Member

spydon commented Dec 18, 2021

Exactly: this is where it gets confusing. I understand onMount for the Component class. But the Game class is a different story. So the question is: what is onMount in the Game class, and how is it different from the onAttach handler?

Yeah, I see the confusion. We should remove onMount and onRemove from the game mixin (I must have accidentally put them there) and in FlameGame we should call onMount from onAttach and onRemove from onDetach probably. Since a game can be added as a child to another component, there will still be a difference to them.

@spydon spydon enabled auto-merge (squash) December 27, 2021 18:49
@spydon spydon merged commit b1f6a34 into flame-engine:main Dec 27, 2021
@st-pasha st-pasha deleted the ps/cleaner-loadable branch December 27, 2021 19:47
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.

Remove onMount/onRemove from Loadable
2 participants