Support nested batches (without combining their constraints) #52
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.
I have a feeling that you guys may have already considered this, but I thought I'd suggest this nested constraint batch implementation. IDK how this fits in conceptually, so treat this as a proposal.
Right now Anchorage does not support nested batches at all and trying to create one while another batch is already in place is considered programming error. However, after I started using Anchorage extensively, I've found that this gets in the way every now and then, with higher-level code suddenly having to care/know about whether lower-level code is using batches to set up its constraints or not. At the same time, a naïve nested batch implementation is trivial to implement. Which is what this PR is about.
Instead of keeping a global reference to a single (optional) active batch, I've expanded the concept to store a stack of active batches in an array, with newly created constraints being recorded into the most recent batch in the global “stack”. Now, this implementation keeps all the nested batches completely isolated from each other (i. e. constraints added to any of the nested batches would not appear and would not be affected by the
active
flag of the batches higher up in the batch stack). It feels reasonably intuitive to me, but I guess others might feel different.Thoughts?