From 312cd9f0ea62717e81b4e7e2d67235fae643c0c8 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Tue, 12 Feb 2019 16:27:31 +0100 Subject: [PATCH] refactor(drag-drop): don't clone items array inside withItems (#15103) Currently when the consumer passes in an array of items to `withItems`, we clone the array which means that the indices won't update if the consumer shuffles them around. The original rationale behind it was to avoid accidentally mutating the array, however this makes it less convenient to use since the consumer would have to remember to move the item in the array __and__ call `withItems` in order to keep everything in sync when an item is dropped. These changes remove the cloning and use `ReadonlyArray` to prevent us from accidentally making changes. Fixes #15089. --- src/cdk/drag-drop/drop-list-ref.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cdk/drag-drop/drop-list-ref.ts b/src/cdk/drag-drop/drop-list-ref.ts index 26dd62ee73c..1d121b01ea2 100644 --- a/src/cdk/drag-drop/drop-list-ref.ts +++ b/src/cdk/drag-drop/drop-list-ref.ts @@ -130,10 +130,10 @@ export class DropListRef { private _previousSwap = {drag: null as DragRef | null, delta: 0}; /** Draggable items in the container. */ - private _draggables: DragRef[]; + private _draggables: ReadonlyArray; /** Drop lists that are connected to the current one. */ - private _siblings: DropListRef[] = []; + private _siblings: ReadonlyArray = []; /** Direction in which the list is oriented. */ private _orientation: 'horizontal' | 'vertical' = 'vertical'; @@ -256,7 +256,7 @@ export class DropListRef { * @param items Items that are a part of this list. */ withItems(items: DragRef[]): this { - this._draggables = items.slice(); + this._draggables = items; items.forEach(item => item._withDropContainer(this)); return this; }