commit 6cd1f207d2e27c3a55e1f29b861330d6e6b0d3be Author: Ole Date: Fri Oct 9 20:34:46 2020 +0200 Refactor reload 8: Extract getting layers This function is very hard to follow. Making small steps to ensure careful review. Making this function a bit shorter, and also simplifying the array concatenation a lot. Change-Id: Ie0529226681f786e5e2500ebffa3f7bd120dccf0 diff --git a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.ts b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.ts index c9351b1..52bd560 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.ts +++ b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.ts @@ -335,15 +335,7 @@ export class GrDiffHost extends GestureEventListeners( this._errorMessage = null; const whitespaceLevel = this._getIgnoreWhitespace(); - const layers: DiffLayer[] = [this.$.syntaxLayer]; - // Get layers from plugins (if any). - for (const pluginLayer of this.$.jsAPI.getDiffLayers( - this.path, - this.changeNum - )) { - layers.push(pluginLayer); - } - this._layers = layers; + this._layers = this._getLayers(this.path, this.changeNum); if (shouldReportMetric) { // We listen on render viewport only on DiffPage (on paramsChanged) @@ -399,6 +391,11 @@ export class GrDiffHost extends GestureEventListeners( this._loading = false; } + private _getLayers(path: string, changeNum: NumericChangeId): DiffLayer[] { + // Get layers from plugins (if any). + return [this.$.syntaxLayer, ...this.$.jsAPI.getDiffLayers(path, changeNum)]; + } + clear() { if (this.path) this.$.jsAPI.disposeDiffLayers(this.path); this._layers = [];