function rowMoved(rows: List<any>, { row, prevRowId }) { const currIndex = indexForRow(rows, row.id); if (currIndex > -1) { const row = rows.get(currIndex); rows = rows.delete(currIndex); const newIndex = nextRowIndex(rows, prevRowId); rows = rows.splice(newIndex, 0, row).toList(); return rows; } return rows; }
(cellOrder: List<CellId>) => { const oldIndex = cellOrder.findIndex( (id: string) => id === action.payload.id ); const newIndex = cellOrder.findIndex( (id: string) => id === action.payload.destinationId ) + (action.payload.above ? 0 : 1); if (oldIndex === newIndex) { return cellOrder; } return cellOrder .splice(oldIndex, 1) .splice(newIndex - (oldIndex < newIndex ? 1 : 0), 0, action.payload.id); }
function rowAdded<T>(rows: List<T>, { row, prevRowId }): List<T> { const index = nextRowIndex(rows, prevRowId); return rows.splice(index, 0, row).toList(); }