applyTo method
Applies every step to document alone, sharing one batch across
consecutive built-in steps. Builders use it to read a staged document
without replaying each step against a fresh copy.
Implementation
DiagramDocument applyTo(DiagramDocument document) {
DiagramDocumentBatch? batch;
for (final step in steps) {
if (step is _BatchStep) {
step.applyTo(batch ??= DiagramDocumentBatch(document));
} else {
if (batch != null) document = batch.build();
batch = null;
document = step.apply(document);
}
}
return batch?.build() ?? document;
}