Skip to content

Commit 312cd9f

Browse files
crisbetojelbourn
authored andcommitted
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.
1 parent 2652532 commit 312cd9f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/cdk/drag-drop/drop-list-ref.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ export class DropListRef<T = any> {
130130
private _previousSwap = {drag: null as DragRef | null, delta: 0};
131131

132132
/** Draggable items in the container. */
133-
private _draggables: DragRef[];
133+
private _draggables: ReadonlyArray<DragRef>;
134134

135135
/** Drop lists that are connected to the current one. */
136-
private _siblings: DropListRef[] = [];
136+
private _siblings: ReadonlyArray<DropListRef> = [];
137137

138138
/** Direction in which the list is oriented. */
139139
private _orientation: 'horizontal' | 'vertical' = 'vertical';
@@ -256,7 +256,7 @@ export class DropListRef<T = any> {
256256
* @param items Items that are a part of this list.
257257
*/
258258
withItems(items: DragRef[]): this {
259-
this._draggables = items.slice();
259+
this._draggables = items;
260260
items.forEach(item => item._withDropContainer(this));
261261
return this;
262262
}

0 commit comments

Comments
 (0)