feat: multiple appended/prepended items#214
Draft
gp-lnuff wants to merge 2 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently,
append()andprepend()accept anarrayorClosureto append/prepend one item to the tree.This limitation is due to two factors:
Previously in those same functions, and more recently in
getAppendedItems()andgetPrependedItems(), there is a hard check for'value'and'name'keys in the suppliedarrayor thearraytheClosureis expected to resolve to.Collection'sprependmethod expects exactly one$value, andpush's...$valueis a variadic parameter, so passing a nestedarrayto it would break the structure of the tree.The solution is to use
Generators:two new
protectedmethods,generatePrependedItems()andgenerateAppendedItems()have been added, toyieldmultiple tree elements from$this->prependand$this->append, be they anarrayor aClosure.in
getTree(), by usingunshift()instead ofprepend(), multiple values can be prepended. By using the...unpacking operator on the newGenerators, the values areyielded and fed into the methods like a variadic parameter.the logic in
getAppendedItems()andgetPrependedItems()has been deferred to theGenerators, and those helpers now fetch the resolved items from them.Naturally, this change is strictly an enhancement and does not introduce regressions to my knowledge (local manual testing), single-item append/prepend is handled as it has been.
This PR needs to:
merge the latest upstream PR
update documentation
I'd move along with those two points if the feature is greenlit.