Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
severo committed Feb 10, 2025
1 parent 3c95980 commit 31336e6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ export function resolvablePromise<T>(): ResolvablePromise<T> {
promise.reject = reject!
return promise
}

5 changes: 2 additions & 3 deletions src/selection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DataFrame, asyncRows } from './dataframe.js'
import { DataFrame } from './dataframe.js'
import { OrderBy } from './TableHeader.js'


/**
* A selection is modelled as an array of ordered and non-overlapping ranges.
* The ranges are separated, ie. the end of one range is strictly less than the start of the next range.
Expand Down Expand Up @@ -226,7 +225,7 @@ export async function getSortIndex({ data, orderBy }: { data: DataFrame, orderBy
if (!header.includes(column)) {
throw new Error('orderBy column is not in the data frame')
}
const dataIndexes = await Promise.all(asyncRows(rows(0, numRows, column), numRows, header).map(row => row.__index__))
const dataIndexes = await Promise.all(rows(0, numRows, column).map(row => row.index))
const tableIndexes = Array.from({ length: numRows }, (_, i) => -1)
for (let i = 0; i < numRows; i++) {
const dataIndex = dataIndexes[i]
Expand Down
19 changes: 13 additions & 6 deletions test/selection.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { describe, expect, it, test } from 'vitest'
import { AsyncRow, DataFrame, Row, sortableDataFrame, wrapPromise } from '../src/dataframe.js'
import { DataFrame, sortableDataFrame } from '../src/dataframe.js'
import { wrapPromise } from '../src/promise.js'
import { AsyncRow, Row } from '../src/row.js'
import { areAllSelected, areValidRanges, extendFromAnchor, isSelected, isValidIndex, isValidRange, selectRange, toTableSelection, toggleAll, toggleIndex, unselectRange } from '../src/selection.js'

describe('an index', () => {
Expand Down Expand Up @@ -215,13 +217,18 @@ const data = [
{ id: 1, name: 'Alice', age: 30 },
{ id: 2, name: 'Bob', age: 20 },
{ id: 4, name: 'Dani', age: 20 },
]
].map((cells, index) => ({ cells, index }))

export function wrapObject(obj: Row): AsyncRow {
return Object.fromEntries(
Object.entries(obj).map(([key, value]) => [key, wrapPromise(value)])
)

export function wrapObject({ index, cells }: Row): AsyncRow {
return {
index: wrapPromise(index),
cells: Object.fromEntries(
Object.entries(cells).map(([key, value]) => [key, wrapPromise(value)])
),
}
}

const dataFrame: DataFrame = {
header: ['id', 'name', 'age'],
numRows: data.length,
Expand Down

0 comments on commit 31336e6

Please sign in to comment.