refactor!: Separate ComponentSet from the Component #1266
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Currently,
ComponentSet
is tightly coupled with theComponent
class and is partially responsible for handling theComponent
's lifecycle.This PR breaks the two classes apart:
Component
will now perform its own lifecycle management, andComponentSet
will focus on being a simple container.Several optional breaking changes introduced here. "Optional" because they can be reverted, at the cost of making the code less nice. However, since
ComponentSet
is mostly internal class, I deem the risk to end users low:Component.reAddChildren()
was made private. Calling it by end users was dangerous.Component.prepare()
declared protected. Likewise, it was never intended to be user-callable.ComponentSet
no longer has fieldparent
, as it is no longer needed.ComponentSet
constructor no longer has argumentComponent parent
, same forComponentSet.createDefault
.ComponentSet
's constructor anyway, I use this opportunity to also change thecomparator
into a named argument, which allows it to be optional, so that no-argumentComponentSet()
would create the component set with default comparator function. This also allowsComponentSet.createDefault
to be greatly simplified, and in fact we will be able to remove it in Dart 2.15.ComponentSet.addChildren()
removed.ComponentSet.add()
andComponentSet.addAll()
are now prohibited (thus, the user can no longer saymyComponent.children.add(newComponent)
). In fact, it would be nice to prohibit direct manipulation ofComponentSet
by the user altogether, but this PR doesn't go that far.Out of scope for this PR: methods for removal of components.
Checklist
fix:
,feat:
,docs:
etc).docs
and added dartdoc comments with///
.examples
.Breaking Change
!
,e.g.
feat!:
,fix!:
).