@tanstack/table-core 9.0.0-beta.31 → 9.0.0-beta.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/cells/constructCell.cjs +1 -4
- package/dist/core/cells/constructCell.cjs.map +1 -1
- package/dist/core/cells/constructCell.d.cts +1 -1
- package/dist/core/cells/constructCell.d.ts +1 -1
- package/dist/core/cells/constructCell.js +1 -4
- package/dist/core/cells/constructCell.js.map +1 -1
- package/dist/core/cells/coreCellsFeature.types.d.cts +1 -1
- package/dist/core/cells/coreCellsFeature.types.d.ts +1 -1
- package/dist/core/cells/coreCellsFeature.utils.d.cts +1 -1
- package/dist/core/cells/coreCellsFeature.utils.d.ts +1 -1
- package/dist/core/columns/constructColumn.cjs +3 -9
- package/dist/core/columns/constructColumn.cjs.map +1 -1
- package/dist/core/columns/constructColumn.js +3 -9
- package/dist/core/columns/constructColumn.js.map +1 -1
- package/dist/core/columns/coreColumnsFeature.cjs +12 -18
- package/dist/core/columns/coreColumnsFeature.cjs.map +1 -1
- package/dist/core/columns/coreColumnsFeature.js +12 -18
- package/dist/core/columns/coreColumnsFeature.js.map +1 -1
- package/dist/core/columns/coreColumnsFeature.utils.cjs +2 -6
- package/dist/core/columns/coreColumnsFeature.utils.cjs.map +1 -1
- package/dist/core/columns/coreColumnsFeature.utils.js +2 -6
- package/dist/core/columns/coreColumnsFeature.utils.js.map +1 -1
- package/dist/core/headers/buildHeaderGroups.cjs +1 -2
- package/dist/core/headers/buildHeaderGroups.cjs.map +1 -1
- package/dist/core/headers/buildHeaderGroups.js +1 -2
- package/dist/core/headers/buildHeaderGroups.js.map +1 -1
- package/dist/core/headers/constructHeader.cjs +1 -4
- package/dist/core/headers/constructHeader.cjs.map +1 -1
- package/dist/core/headers/constructHeader.js +1 -4
- package/dist/core/headers/constructHeader.js.map +1 -1
- package/dist/core/headers/coreHeadersFeature.cjs +8 -11
- package/dist/core/headers/coreHeadersFeature.cjs.map +1 -1
- package/dist/core/headers/coreHeadersFeature.js +8 -11
- package/dist/core/headers/coreHeadersFeature.js.map +1 -1
- package/dist/core/headers/coreHeadersFeature.utils.cjs +2 -4
- package/dist/core/headers/coreHeadersFeature.utils.cjs.map +1 -1
- package/dist/core/headers/coreHeadersFeature.utils.js +2 -4
- package/dist/core/headers/coreHeadersFeature.utils.js.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.types.d.cts +3 -3
- package/dist/core/row-models/coreRowModelsFeature.types.d.ts +3 -3
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs +6 -24
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.d.cts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.d.ts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.js +6 -24
- package/dist/core/row-models/coreRowModelsFeature.utils.js.map +1 -1
- package/dist/core/row-models/createCoreRowModel.cjs +2 -3
- package/dist/core/row-models/createCoreRowModel.cjs.map +1 -1
- package/dist/core/row-models/createCoreRowModel.d.cts +1 -1
- package/dist/core/row-models/createCoreRowModel.d.ts +1 -1
- package/dist/core/row-models/createCoreRowModel.js +2 -3
- package/dist/core/row-models/createCoreRowModel.js.map +1 -1
- package/dist/core/rows/constructRow.cjs +2 -8
- package/dist/core/rows/constructRow.cjs.map +1 -1
- package/dist/core/rows/constructRow.js +2 -8
- package/dist/core/rows/constructRow.js.map +1 -1
- package/dist/core/rows/coreRowsFeature.types.d.cts +1 -1
- package/dist/core/rows/coreRowsFeature.types.d.ts +1 -1
- package/dist/core/rows/coreRowsFeature.utils.cjs +3 -4
- package/dist/core/rows/coreRowsFeature.utils.cjs.map +1 -1
- package/dist/core/rows/coreRowsFeature.utils.d.cts +1 -1
- package/dist/core/rows/coreRowsFeature.utils.d.ts +1 -1
- package/dist/core/rows/coreRowsFeature.utils.js +3 -4
- package/dist/core/rows/coreRowsFeature.utils.js.map +1 -1
- package/dist/core/table/constructTable.cjs +4 -10
- package/dist/core/table/constructTable.cjs.map +1 -1
- package/dist/core/table/constructTable.js +4 -10
- package/dist/core/table/constructTable.js.map +1 -1
- package/dist/experimental-worker-plugin.cjs +14 -0
- package/dist/experimental-worker-plugin.d.cts +5 -0
- package/dist/experimental-worker-plugin.d.ts +5 -0
- package/dist/experimental-worker-plugin.js +6 -0
- package/dist/features/column-faceting/columnFacetingFeature.cjs +12 -18
- package/dist/features/column-faceting/columnFacetingFeature.cjs.map +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.js +12 -18
- package/dist/features/column-faceting/columnFacetingFeature.js.map +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.types.d.cts +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.types.d.ts +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.utils.cjs +7 -25
- package/dist/features/column-faceting/columnFacetingFeature.utils.cjs.map +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.utils.d.cts +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.utils.d.ts +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.utils.js +7 -25
- package/dist/features/column-faceting/columnFacetingFeature.utils.js.map +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.cjs +8 -14
- package/dist/features/column-faceting/createFacetedRowModel.cjs.map +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.d.cts +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.d.ts +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.js +8 -14
- package/dist/features/column-faceting/createFacetedRowModel.js.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs +10 -13
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.js +10 -13
- package/dist/features/column-filtering/columnFilteringFeature.utils.js.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.cjs +12 -18
- package/dist/features/column-filtering/createFilteredRowModel.cjs.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.d.cts +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.d.ts +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.js +12 -18
- package/dist/features/column-filtering/createFilteredRowModel.js.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.cjs +1 -4
- package/dist/features/column-grouping/columnGroupingFeature.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.js +1 -4
- package/dist/features/column-grouping/columnGroupingFeature.js.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.types.d.cts +4 -4
- package/dist/features/column-grouping/columnGroupingFeature.types.d.ts +4 -4
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +8 -13
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +2 -2
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +2 -2
- package/dist/features/column-grouping/columnGroupingFeature.utils.js +8 -13
- package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.cjs +3 -7
- package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.d.cts +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.d.ts +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.js +3 -7
- package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.cjs +13 -19
- package/dist/features/column-ordering/columnOrderingFeature.cjs.map +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.js +13 -19
- package/dist/features/column-ordering/columnOrderingFeature.js.map +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.utils.cjs +6 -11
- package/dist/features/column-ordering/columnOrderingFeature.utils.cjs.map +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.utils.js +6 -11
- package/dist/features/column-ordering/columnOrderingFeature.utils.js.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.cjs +78 -114
- package/dist/features/column-pinning/columnPinningFeature.cjs.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.js +78 -114
- package/dist/features/column-pinning/columnPinningFeature.js.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.types.d.cts +1 -1
- package/dist/features/column-pinning/columnPinningFeature.types.d.ts +1 -1
- package/dist/features/column-pinning/columnPinningFeature.utils.cjs +15 -28
- package/dist/features/column-pinning/columnPinningFeature.utils.cjs.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.utils.d.cts +2 -2
- package/dist/features/column-pinning/columnPinningFeature.utils.d.ts +2 -2
- package/dist/features/column-pinning/columnPinningFeature.utils.js +15 -28
- package/dist/features/column-pinning/columnPinningFeature.utils.js.map +1 -1
- package/dist/features/column-resizing/columnResizingFeature.utils.cjs +12 -16
- package/dist/features/column-resizing/columnResizingFeature.utils.cjs.map +1 -1
- package/dist/features/column-resizing/columnResizingFeature.utils.js +12 -16
- package/dist/features/column-resizing/columnResizingFeature.utils.js.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.cjs +24 -48
- package/dist/features/column-sizing/columnSizingFeature.cjs.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.js +24 -48
- package/dist/features/column-sizing/columnSizingFeature.js.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.utils.cjs +11 -18
- package/dist/features/column-sizing/columnSizingFeature.utils.cjs.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.utils.d.cts +1 -1
- package/dist/features/column-sizing/columnSizingFeature.utils.d.ts +1 -1
- package/dist/features/column-sizing/columnSizingFeature.utils.js +11 -18
- package/dist/features/column-sizing/columnSizingFeature.utils.js.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.cjs +25 -40
- package/dist/features/column-visibility/columnVisibilityFeature.cjs.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.js +25 -40
- package/dist/features/column-visibility/columnVisibilityFeature.js.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.types.d.cts +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.types.d.ts +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.utils.cjs +3 -6
- package/dist/features/column-visibility/columnVisibilityFeature.utils.cjs.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.utils.d.cts +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.utils.d.ts +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.utils.js +3 -6
- package/dist/features/column-visibility/columnVisibilityFeature.utils.js.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.cjs +1 -2
- package/dist/features/global-filtering/globalFilteringFeature.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.js +1 -2
- package/dist/features/global-filtering/globalFilteringFeature.js.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs +3 -5
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.js +3 -5
- package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
- package/dist/features/row-expanding/createExpandedRowModel.cjs +6 -10
- package/dist/features/row-expanding/createExpandedRowModel.cjs.map +1 -1
- package/dist/features/row-expanding/createExpandedRowModel.d.cts +1 -1
- package/dist/features/row-expanding/createExpandedRowModel.d.ts +1 -1
- package/dist/features/row-expanding/createExpandedRowModel.js +6 -10
- package/dist/features/row-expanding/createExpandedRowModel.js.map +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.types.d.cts +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.types.d.ts +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.utils.cjs +8 -15
- package/dist/features/row-expanding/rowExpandingFeature.utils.cjs.map +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.utils.js +8 -15
- package/dist/features/row-expanding/rowExpandingFeature.utils.js.map +1 -1
- package/dist/features/row-pagination/createPaginatedRowModel.cjs +6 -10
- package/dist/features/row-pagination/createPaginatedRowModel.cjs.map +1 -1
- package/dist/features/row-pagination/createPaginatedRowModel.d.cts +1 -1
- package/dist/features/row-pagination/createPaginatedRowModel.d.ts +1 -1
- package/dist/features/row-pagination/createPaginatedRowModel.js +6 -10
- package/dist/features/row-pagination/createPaginatedRowModel.js.map +1 -1
- package/dist/features/row-pagination/rowPaginationFeature.types.d.cts +1 -1
- package/dist/features/row-pagination/rowPaginationFeature.types.d.ts +1 -1
- package/dist/features/row-pagination/rowPaginationFeature.utils.cjs +8 -14
- package/dist/features/row-pagination/rowPaginationFeature.utils.cjs.map +1 -1
- package/dist/features/row-pagination/rowPaginationFeature.utils.js +8 -14
- package/dist/features/row-pagination/rowPaginationFeature.utils.js.map +1 -1
- package/dist/features/row-pinning/rowPinningFeature.cjs +4 -16
- package/dist/features/row-pinning/rowPinningFeature.cjs.map +1 -1
- package/dist/features/row-pinning/rowPinningFeature.js +4 -16
- package/dist/features/row-pinning/rowPinningFeature.js.map +1 -1
- package/dist/features/row-pinning/rowPinningFeature.utils.cjs +7 -12
- package/dist/features/row-pinning/rowPinningFeature.utils.cjs.map +1 -1
- package/dist/features/row-pinning/rowPinningFeature.utils.js +7 -12
- package/dist/features/row-pinning/rowPinningFeature.utils.js.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.cjs +30 -60
- package/dist/features/row-selection/rowSelectionFeature.cjs.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.js +30 -60
- package/dist/features/row-selection/rowSelectionFeature.js.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.types.d.cts +1 -1
- package/dist/features/row-selection/rowSelectionFeature.types.d.ts +1 -1
- package/dist/features/row-selection/rowSelectionFeature.utils.cjs +10 -17
- package/dist/features/row-selection/rowSelectionFeature.utils.cjs.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.utils.d.cts +1 -1
- package/dist/features/row-selection/rowSelectionFeature.utils.d.ts +1 -1
- package/dist/features/row-selection/rowSelectionFeature.utils.js +10 -17
- package/dist/features/row-selection/rowSelectionFeature.utils.js.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.cjs +3 -7
- package/dist/features/row-sorting/createSortedRowModel.cjs.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.d.cts +1 -1
- package/dist/features/row-sorting/createSortedRowModel.d.ts +1 -1
- package/dist/features/row-sorting/createSortedRowModel.js +3 -7
- package/dist/features/row-sorting/createSortedRowModel.js.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.types.d.cts +2 -2
- package/dist/features/row-sorting/rowSortingFeature.types.d.ts +2 -2
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs +9 -13
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.js +9 -13
- package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
- package/dist/flex-render.d.cts +1 -1
- package/dist/flex-render.d.ts +1 -1
- package/dist/fns/filterFns.cjs +8 -12
- package/dist/fns/filterFns.cjs.map +1 -1
- package/dist/fns/filterFns.js +8 -12
- package/dist/fns/filterFns.js.map +1 -1
- package/dist/index.d.cts +16 -16
- package/dist/index.d.ts +16 -16
- package/dist/store-reactivity-bindings.cjs +2 -2
- package/dist/store-reactivity-bindings.cjs.map +1 -1
- package/dist/store-reactivity-bindings.js +2 -2
- package/dist/store-reactivity-bindings.js.map +1 -1
- package/dist/types/Cell.d.cts +1 -1
- package/dist/types/Cell.d.ts +1 -1
- package/dist/types/Column.d.cts +7 -7
- package/dist/types/Column.d.ts +7 -7
- package/dist/types/ColumnDef.d.cts +6 -6
- package/dist/types/ColumnDef.d.ts +6 -6
- package/dist/types/Header.d.cts +1 -1
- package/dist/types/Header.d.ts +1 -1
- package/dist/types/Row.d.cts +2 -2
- package/dist/types/Row.d.ts +2 -2
- package/dist/types/RowModel.d.cts +4 -4
- package/dist/types/RowModel.d.ts +4 -4
- package/dist/types/RowModelFns.d.cts +2 -2
- package/dist/types/RowModelFns.d.ts +2 -2
- package/dist/types/Table.d.cts +9 -9
- package/dist/types/Table.d.ts +9 -9
- package/dist/types/TableFeatures.d.cts +4 -4
- package/dist/types/TableFeatures.d.ts +4 -4
- package/dist/types/TableOptions.d.cts +7 -7
- package/dist/types/TableOptions.d.ts +7 -7
- package/dist/types/TableState.d.cts +6 -6
- package/dist/types/TableState.d.ts +6 -6
- package/dist/utils.cjs +9 -12
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.js +9 -12
- package/dist/utils.js.map +1 -1
- package/dist/worker/createTableWorker.cjs +189 -0
- package/dist/worker/createTableWorker.cjs.map +1 -0
- package/dist/worker/createTableWorker.d.cts +102 -0
- package/dist/worker/createTableWorker.d.ts +102 -0
- package/dist/worker/createTableWorker.js +186 -0
- package/dist/worker/createTableWorker.js.map +1 -0
- package/dist/worker/createWorkerRowModel.cjs +78 -0
- package/dist/worker/createWorkerRowModel.cjs.map +1 -0
- package/dist/worker/createWorkerRowModel.d.cts +42 -0
- package/dist/worker/createWorkerRowModel.d.ts +42 -0
- package/dist/worker/createWorkerRowModel.js +78 -0
- package/dist/worker/createWorkerRowModel.js.map +1 -0
- package/dist/worker/initTableWorker.cjs +100 -0
- package/dist/worker/initTableWorker.cjs.map +1 -0
- package/dist/worker/initTableWorker.d.cts +33 -0
- package/dist/worker/initTableWorker.d.ts +33 -0
- package/dist/worker/initTableWorker.js +100 -0
- package/dist/worker/initTableWorker.js.map +1 -0
- package/dist/worker/rebuildRowModel.cjs +72 -0
- package/dist/worker/rebuildRowModel.cjs.map +1 -0
- package/dist/worker/rebuildRowModel.d.cts +9 -0
- package/dist/worker/rebuildRowModel.d.ts +9 -0
- package/dist/worker/rebuildRowModel.js +72 -0
- package/dist/worker/rebuildRowModel.js.map +1 -0
- package/dist/worker/serializeRowModel.cjs +53 -0
- package/dist/worker/serializeRowModel.cjs.map +1 -0
- package/dist/worker/serializeRowModel.js +52 -0
- package/dist/worker/serializeRowModel.js.map +1 -0
- package/dist/worker/tableWorkerProtocol.cjs +29 -0
- package/dist/worker/tableWorkerProtocol.cjs.map +1 -0
- package/dist/worker/tableWorkerProtocol.d.cts +88 -0
- package/dist/worker/tableWorkerProtocol.d.ts +88 -0
- package/dist/worker/tableWorkerProtocol.js +27 -0
- package/dist/worker/tableWorkerProtocol.js.map +1 -0
- package/package.json +6 -2
- package/src/experimental-worker-plugin.ts +22 -0
- package/src/worker/createTableWorker.ts +357 -0
- package/src/worker/createWorkerRowModel.ts +121 -0
- package/src/worker/initTableWorker.ts +164 -0
- package/src/worker/rebuildRowModel.ts +117 -0
- package/src/worker/serializeRowModel.ts +80 -0
- package/src/worker/tableWorkerProtocol.ts +105 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/worker/tableWorkerProtocol.ts
|
|
3
|
+
/**
|
|
4
|
+
* Row model stages that can be offloaded to the worker, in pipeline order.
|
|
5
|
+
* Everything else in this module is derived from this list; adding a stage
|
|
6
|
+
* means adding an entry here and to `tableWorkerStageStateDeps`.
|
|
7
|
+
*/
|
|
8
|
+
const tableWorkerPipeline = [
|
|
9
|
+
"filtered",
|
|
10
|
+
"grouped",
|
|
11
|
+
"sorted",
|
|
12
|
+
"expanded"
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* The state slices each stage's computation depends on. The main thread sends
|
|
16
|
+
* the union of deps for its registered stages; a change to any of them
|
|
17
|
+
* triggers one worker round trip.
|
|
18
|
+
*/
|
|
19
|
+
const tableWorkerStageStateDeps = {
|
|
20
|
+
filtered: ["columnFilters", "globalFilter"],
|
|
21
|
+
grouped: ["grouping"],
|
|
22
|
+
sorted: ["sorting"],
|
|
23
|
+
expanded: ["expanded"]
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.tableWorkerPipeline = tableWorkerPipeline;
|
|
28
|
+
exports.tableWorkerStageStateDeps = tableWorkerStageStateDeps;
|
|
29
|
+
//# sourceMappingURL=tableWorkerProtocol.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tableWorkerProtocol.cjs","names":[],"sources":["../../src/worker/tableWorkerProtocol.ts"],"sourcesContent":["import type { RowData } from '../types/type-utils'\n\n/**\n * Row model stages that can be offloaded to the worker, in pipeline order.\n * Everything else in this module is derived from this list; adding a stage\n * means adding an entry here and to `tableWorkerStageStateDeps`.\n */\nexport const tableWorkerPipeline = [\n 'filtered',\n 'grouped',\n 'sorted',\n 'expanded',\n] as const\n\nexport type TableWorkerStage = (typeof tableWorkerPipeline)[number]\n\n/**\n * The state slices each stage's computation depends on. The main thread sends\n * the union of deps for its registered stages; a change to any of them\n * triggers one worker round trip.\n */\nexport const tableWorkerStageStateDeps: Record<\n TableWorkerStage,\n Array<string>\n> = {\n filtered: ['columnFilters', 'globalFilter'],\n grouped: ['grouping'],\n sorted: ['sorting'],\n expanded: ['expanded'],\n}\n\n/**\n * A serialized synthetic (group) row. Leaf rows serialize as their position in\n * `options.data`; group rows carry what `constructRow` + the grouped row model\n * need to rebuild them, plus eagerly computed aggregate values so no\n * aggregation runs on the main thread.\n */\nexport interface TableWorkerGroupNode {\n id: string\n groupingColumnId: string\n groupingValue: unknown\n index: number\n aggregates: Record<string, unknown>\n children: Array<TableWorkerRowNode>\n}\n\nexport type TableWorkerRowNode = number | TableWorkerGroupNode\n\n/**\n * A stage result. Flat models (every row is a data row) travel as a\n * transferable index permutation; models containing synthetic rows (grouping)\n * travel as a tree. The kind is chosen from the model's actual shape at\n * runtime, not from the stage name: a sorted model is flat without grouping\n * and a tree with it.\n *\n * `unchanged` means the stage's model is identical to the last one sent for\n * this dataset (its memoized inputs did not change); the main thread keeps\n * its previous result and skips the rebuild entirely.\n */\nexport type TableWorkerStagePayload =\n | { kind: 'flat'; indices: Uint32Array }\n | { kind: 'tree'; children: Array<TableWorkerRowNode> }\n | { kind: 'unchanged' }\n\nexport type TableWorkerRequest<TData extends RowData = any> =\n | {\n type: 'data'\n dataVersion: number\n data: Array<TData>\n }\n | {\n type: 'process'\n requestId: number\n dataVersion: number\n /** The stages the main thread has worker-backed row models for. */\n stages: Array<TableWorkerStage>\n /** Serializable state slices (union of the stages' deps). */\n state: Record<string, unknown>\n }\n\nexport interface TableWorkerResult {\n type: 'result'\n requestId: number\n dataVersion: number\n stages: { [K in TableWorkerStage]?: TableWorkerStagePayload }\n computeMs: number\n}\n\nexport type TableWorkerResponse = TableWorkerResult\n\n/**\n * The state slice added by `workerRowModelsFeature`. `version` bumps when a\n * worker result lands (driving re-renders through the normal state path);\n * `isPending` is true while a request is in flight. The timing fields expose\n * the last result's worker compute time and full round trip for devtools and\n * debugging.\n */\nexport interface TableState_WorkerRowModels {\n workerRowModels: {\n version: number\n isPending: boolean\n lastComputeMs?: number\n lastRoundTripMs?: number\n }\n}\n"],"mappings":";;;;;;;AAOA,MAAa,sBAAsB;CACjC;CACA;CACA;CACA;AACF;;;;;;AASA,MAAa,4BAGT;CACF,UAAU,CAAC,iBAAiB,cAAc;CAC1C,SAAS,CAAC,UAAU;CACpB,QAAQ,CAAC,SAAS;CAClB,UAAU,CAAC,UAAU;AACvB"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { RowData } from "../types/type-utils.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/worker/tableWorkerProtocol.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Row model stages that can be offloaded to the worker, in pipeline order.
|
|
6
|
+
* Everything else in this module is derived from this list; adding a stage
|
|
7
|
+
* means adding an entry here and to `tableWorkerStageStateDeps`.
|
|
8
|
+
*/
|
|
9
|
+
declare const tableWorkerPipeline: readonly ["filtered", "grouped", "sorted", "expanded"];
|
|
10
|
+
type TableWorkerStage = (typeof tableWorkerPipeline)[number];
|
|
11
|
+
/**
|
|
12
|
+
* The state slices each stage's computation depends on. The main thread sends
|
|
13
|
+
* the union of deps for its registered stages; a change to any of them
|
|
14
|
+
* triggers one worker round trip.
|
|
15
|
+
*/
|
|
16
|
+
declare const tableWorkerStageStateDeps: Record<TableWorkerStage, Array<string>>;
|
|
17
|
+
/**
|
|
18
|
+
* A serialized synthetic (group) row. Leaf rows serialize as their position in
|
|
19
|
+
* `options.data`; group rows carry what `constructRow` + the grouped row model
|
|
20
|
+
* need to rebuild them, plus eagerly computed aggregate values so no
|
|
21
|
+
* aggregation runs on the main thread.
|
|
22
|
+
*/
|
|
23
|
+
interface TableWorkerGroupNode {
|
|
24
|
+
id: string;
|
|
25
|
+
groupingColumnId: string;
|
|
26
|
+
groupingValue: unknown;
|
|
27
|
+
index: number;
|
|
28
|
+
aggregates: Record<string, unknown>;
|
|
29
|
+
children: Array<TableWorkerRowNode>;
|
|
30
|
+
}
|
|
31
|
+
type TableWorkerRowNode = number | TableWorkerGroupNode;
|
|
32
|
+
/**
|
|
33
|
+
* A stage result. Flat models (every row is a data row) travel as a
|
|
34
|
+
* transferable index permutation; models containing synthetic rows (grouping)
|
|
35
|
+
* travel as a tree. The kind is chosen from the model's actual shape at
|
|
36
|
+
* runtime, not from the stage name: a sorted model is flat without grouping
|
|
37
|
+
* and a tree with it.
|
|
38
|
+
*
|
|
39
|
+
* `unchanged` means the stage's model is identical to the last one sent for
|
|
40
|
+
* this dataset (its memoized inputs did not change); the main thread keeps
|
|
41
|
+
* its previous result and skips the rebuild entirely.
|
|
42
|
+
*/
|
|
43
|
+
type TableWorkerStagePayload = {
|
|
44
|
+
kind: 'flat';
|
|
45
|
+
indices: Uint32Array;
|
|
46
|
+
} | {
|
|
47
|
+
kind: 'tree';
|
|
48
|
+
children: Array<TableWorkerRowNode>;
|
|
49
|
+
} | {
|
|
50
|
+
kind: 'unchanged';
|
|
51
|
+
};
|
|
52
|
+
type TableWorkerRequest<TData extends RowData = any> = {
|
|
53
|
+
type: 'data';
|
|
54
|
+
dataVersion: number;
|
|
55
|
+
data: Array<TData>;
|
|
56
|
+
} | {
|
|
57
|
+
type: 'process';
|
|
58
|
+
requestId: number;
|
|
59
|
+
dataVersion: number; /** The stages the main thread has worker-backed row models for. */
|
|
60
|
+
stages: Array<TableWorkerStage>; /** Serializable state slices (union of the stages' deps). */
|
|
61
|
+
state: Record<string, unknown>;
|
|
62
|
+
};
|
|
63
|
+
interface TableWorkerResult {
|
|
64
|
+
type: 'result';
|
|
65
|
+
requestId: number;
|
|
66
|
+
dataVersion: number;
|
|
67
|
+
stages: { [K in TableWorkerStage]?: TableWorkerStagePayload };
|
|
68
|
+
computeMs: number;
|
|
69
|
+
}
|
|
70
|
+
type TableWorkerResponse = TableWorkerResult;
|
|
71
|
+
/**
|
|
72
|
+
* The state slice added by `workerRowModelsFeature`. `version` bumps when a
|
|
73
|
+
* worker result lands (driving re-renders through the normal state path);
|
|
74
|
+
* `isPending` is true while a request is in flight. The timing fields expose
|
|
75
|
+
* the last result's worker compute time and full round trip for devtools and
|
|
76
|
+
* debugging.
|
|
77
|
+
*/
|
|
78
|
+
interface TableState_WorkerRowModels {
|
|
79
|
+
workerRowModels: {
|
|
80
|
+
version: number;
|
|
81
|
+
isPending: boolean;
|
|
82
|
+
lastComputeMs?: number;
|
|
83
|
+
lastRoundTripMs?: number;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
export { TableState_WorkerRowModels, TableWorkerGroupNode, TableWorkerRequest, TableWorkerResponse, TableWorkerResult, TableWorkerRowNode, TableWorkerStage, TableWorkerStagePayload, tableWorkerPipeline, tableWorkerStageStateDeps };
|
|
88
|
+
//# sourceMappingURL=tableWorkerProtocol.d.cts.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { RowData } from "../types/type-utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/worker/tableWorkerProtocol.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Row model stages that can be offloaded to the worker, in pipeline order.
|
|
6
|
+
* Everything else in this module is derived from this list; adding a stage
|
|
7
|
+
* means adding an entry here and to `tableWorkerStageStateDeps`.
|
|
8
|
+
*/
|
|
9
|
+
declare const tableWorkerPipeline: readonly ["filtered", "grouped", "sorted", "expanded"];
|
|
10
|
+
type TableWorkerStage = (typeof tableWorkerPipeline)[number];
|
|
11
|
+
/**
|
|
12
|
+
* The state slices each stage's computation depends on. The main thread sends
|
|
13
|
+
* the union of deps for its registered stages; a change to any of them
|
|
14
|
+
* triggers one worker round trip.
|
|
15
|
+
*/
|
|
16
|
+
declare const tableWorkerStageStateDeps: Record<TableWorkerStage, Array<string>>;
|
|
17
|
+
/**
|
|
18
|
+
* A serialized synthetic (group) row. Leaf rows serialize as their position in
|
|
19
|
+
* `options.data`; group rows carry what `constructRow` + the grouped row model
|
|
20
|
+
* need to rebuild them, plus eagerly computed aggregate values so no
|
|
21
|
+
* aggregation runs on the main thread.
|
|
22
|
+
*/
|
|
23
|
+
interface TableWorkerGroupNode {
|
|
24
|
+
id: string;
|
|
25
|
+
groupingColumnId: string;
|
|
26
|
+
groupingValue: unknown;
|
|
27
|
+
index: number;
|
|
28
|
+
aggregates: Record<string, unknown>;
|
|
29
|
+
children: Array<TableWorkerRowNode>;
|
|
30
|
+
}
|
|
31
|
+
type TableWorkerRowNode = number | TableWorkerGroupNode;
|
|
32
|
+
/**
|
|
33
|
+
* A stage result. Flat models (every row is a data row) travel as a
|
|
34
|
+
* transferable index permutation; models containing synthetic rows (grouping)
|
|
35
|
+
* travel as a tree. The kind is chosen from the model's actual shape at
|
|
36
|
+
* runtime, not from the stage name: a sorted model is flat without grouping
|
|
37
|
+
* and a tree with it.
|
|
38
|
+
*
|
|
39
|
+
* `unchanged` means the stage's model is identical to the last one sent for
|
|
40
|
+
* this dataset (its memoized inputs did not change); the main thread keeps
|
|
41
|
+
* its previous result and skips the rebuild entirely.
|
|
42
|
+
*/
|
|
43
|
+
type TableWorkerStagePayload = {
|
|
44
|
+
kind: 'flat';
|
|
45
|
+
indices: Uint32Array;
|
|
46
|
+
} | {
|
|
47
|
+
kind: 'tree';
|
|
48
|
+
children: Array<TableWorkerRowNode>;
|
|
49
|
+
} | {
|
|
50
|
+
kind: 'unchanged';
|
|
51
|
+
};
|
|
52
|
+
type TableWorkerRequest<TData extends RowData = any> = {
|
|
53
|
+
type: 'data';
|
|
54
|
+
dataVersion: number;
|
|
55
|
+
data: Array<TData>;
|
|
56
|
+
} | {
|
|
57
|
+
type: 'process';
|
|
58
|
+
requestId: number;
|
|
59
|
+
dataVersion: number; /** The stages the main thread has worker-backed row models for. */
|
|
60
|
+
stages: Array<TableWorkerStage>; /** Serializable state slices (union of the stages' deps). */
|
|
61
|
+
state: Record<string, unknown>;
|
|
62
|
+
};
|
|
63
|
+
interface TableWorkerResult {
|
|
64
|
+
type: 'result';
|
|
65
|
+
requestId: number;
|
|
66
|
+
dataVersion: number;
|
|
67
|
+
stages: { [K in TableWorkerStage]?: TableWorkerStagePayload };
|
|
68
|
+
computeMs: number;
|
|
69
|
+
}
|
|
70
|
+
type TableWorkerResponse = TableWorkerResult;
|
|
71
|
+
/**
|
|
72
|
+
* The state slice added by `workerRowModelsFeature`. `version` bumps when a
|
|
73
|
+
* worker result lands (driving re-renders through the normal state path);
|
|
74
|
+
* `isPending` is true while a request is in flight. The timing fields expose
|
|
75
|
+
* the last result's worker compute time and full round trip for devtools and
|
|
76
|
+
* debugging.
|
|
77
|
+
*/
|
|
78
|
+
interface TableState_WorkerRowModels {
|
|
79
|
+
workerRowModels: {
|
|
80
|
+
version: number;
|
|
81
|
+
isPending: boolean;
|
|
82
|
+
lastComputeMs?: number;
|
|
83
|
+
lastRoundTripMs?: number;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
export { TableState_WorkerRowModels, TableWorkerGroupNode, TableWorkerRequest, TableWorkerResponse, TableWorkerResult, TableWorkerRowNode, TableWorkerStage, TableWorkerStagePayload, tableWorkerPipeline, tableWorkerStageStateDeps };
|
|
88
|
+
//# sourceMappingURL=tableWorkerProtocol.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/worker/tableWorkerProtocol.ts
|
|
2
|
+
/**
|
|
3
|
+
* Row model stages that can be offloaded to the worker, in pipeline order.
|
|
4
|
+
* Everything else in this module is derived from this list; adding a stage
|
|
5
|
+
* means adding an entry here and to `tableWorkerStageStateDeps`.
|
|
6
|
+
*/
|
|
7
|
+
const tableWorkerPipeline = [
|
|
8
|
+
"filtered",
|
|
9
|
+
"grouped",
|
|
10
|
+
"sorted",
|
|
11
|
+
"expanded"
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* The state slices each stage's computation depends on. The main thread sends
|
|
15
|
+
* the union of deps for its registered stages; a change to any of them
|
|
16
|
+
* triggers one worker round trip.
|
|
17
|
+
*/
|
|
18
|
+
const tableWorkerStageStateDeps = {
|
|
19
|
+
filtered: ["columnFilters", "globalFilter"],
|
|
20
|
+
grouped: ["grouping"],
|
|
21
|
+
sorted: ["sorting"],
|
|
22
|
+
expanded: ["expanded"]
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { tableWorkerPipeline, tableWorkerStageStateDeps };
|
|
27
|
+
//# sourceMappingURL=tableWorkerProtocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tableWorkerProtocol.js","names":[],"sources":["../../src/worker/tableWorkerProtocol.ts"],"sourcesContent":["import type { RowData } from '../types/type-utils'\n\n/**\n * Row model stages that can be offloaded to the worker, in pipeline order.\n * Everything else in this module is derived from this list; adding a stage\n * means adding an entry here and to `tableWorkerStageStateDeps`.\n */\nexport const tableWorkerPipeline = [\n 'filtered',\n 'grouped',\n 'sorted',\n 'expanded',\n] as const\n\nexport type TableWorkerStage = (typeof tableWorkerPipeline)[number]\n\n/**\n * The state slices each stage's computation depends on. The main thread sends\n * the union of deps for its registered stages; a change to any of them\n * triggers one worker round trip.\n */\nexport const tableWorkerStageStateDeps: Record<\n TableWorkerStage,\n Array<string>\n> = {\n filtered: ['columnFilters', 'globalFilter'],\n grouped: ['grouping'],\n sorted: ['sorting'],\n expanded: ['expanded'],\n}\n\n/**\n * A serialized synthetic (group) row. Leaf rows serialize as their position in\n * `options.data`; group rows carry what `constructRow` + the grouped row model\n * need to rebuild them, plus eagerly computed aggregate values so no\n * aggregation runs on the main thread.\n */\nexport interface TableWorkerGroupNode {\n id: string\n groupingColumnId: string\n groupingValue: unknown\n index: number\n aggregates: Record<string, unknown>\n children: Array<TableWorkerRowNode>\n}\n\nexport type TableWorkerRowNode = number | TableWorkerGroupNode\n\n/**\n * A stage result. Flat models (every row is a data row) travel as a\n * transferable index permutation; models containing synthetic rows (grouping)\n * travel as a tree. The kind is chosen from the model's actual shape at\n * runtime, not from the stage name: a sorted model is flat without grouping\n * and a tree with it.\n *\n * `unchanged` means the stage's model is identical to the last one sent for\n * this dataset (its memoized inputs did not change); the main thread keeps\n * its previous result and skips the rebuild entirely.\n */\nexport type TableWorkerStagePayload =\n | { kind: 'flat'; indices: Uint32Array }\n | { kind: 'tree'; children: Array<TableWorkerRowNode> }\n | { kind: 'unchanged' }\n\nexport type TableWorkerRequest<TData extends RowData = any> =\n | {\n type: 'data'\n dataVersion: number\n data: Array<TData>\n }\n | {\n type: 'process'\n requestId: number\n dataVersion: number\n /** The stages the main thread has worker-backed row models for. */\n stages: Array<TableWorkerStage>\n /** Serializable state slices (union of the stages' deps). */\n state: Record<string, unknown>\n }\n\nexport interface TableWorkerResult {\n type: 'result'\n requestId: number\n dataVersion: number\n stages: { [K in TableWorkerStage]?: TableWorkerStagePayload }\n computeMs: number\n}\n\nexport type TableWorkerResponse = TableWorkerResult\n\n/**\n * The state slice added by `workerRowModelsFeature`. `version` bumps when a\n * worker result lands (driving re-renders through the normal state path);\n * `isPending` is true while a request is in flight. The timing fields expose\n * the last result's worker compute time and full round trip for devtools and\n * debugging.\n */\nexport interface TableState_WorkerRowModels {\n workerRowModels: {\n version: number\n isPending: boolean\n lastComputeMs?: number\n lastRoundTripMs?: number\n }\n}\n"],"mappings":";;;;;;AAOA,MAAa,sBAAsB;CACjC;CACA;CACA;CACA;AACF;;;;;;AASA,MAAa,4BAGT;CACF,UAAU,CAAC,iBAAiB,cAAc;CAC1C,SAAS,CAAC,UAAU;CACpB,QAAQ,CAAC,SAAS;CAClB,UAAU,CAAC,UAAU;AACvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/table-core",
|
|
3
|
-
"version": "9.0.0-beta.
|
|
3
|
+
"version": "9.0.0-beta.33",
|
|
4
4
|
"description": "Headless UI for building powerful tables & datagrids for TS/JS.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,6 +35,10 @@
|
|
|
35
35
|
"import": "./dist/index.js",
|
|
36
36
|
"require": "./dist/index.cjs"
|
|
37
37
|
},
|
|
38
|
+
"./experimental-worker-plugin": {
|
|
39
|
+
"import": "./dist/experimental-worker-plugin.js",
|
|
40
|
+
"require": "./dist/experimental-worker-plugin.cjs"
|
|
41
|
+
},
|
|
38
42
|
"./flex-render": {
|
|
39
43
|
"import": "./dist/flex-render.js",
|
|
40
44
|
"require": "./dist/flex-render.cjs"
|
|
@@ -55,7 +59,7 @@
|
|
|
55
59
|
},
|
|
56
60
|
"sideEffects": false,
|
|
57
61
|
"engines": {
|
|
58
|
-
"node": ">=
|
|
62
|
+
"node": ">=20"
|
|
59
63
|
},
|
|
60
64
|
"files": [
|
|
61
65
|
"dist/",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Worker row models sub-entry (experimental POC).
|
|
3
|
+
*
|
|
4
|
+
* Offloads row model stages to a dedicated worker running a headless "shadow
|
|
5
|
+
* table" built with the same table-core row model pipeline. The main thread
|
|
6
|
+
* receives transferable index permutations and rebuilds its row models from
|
|
7
|
+
* them, stale-while-revalidate style.
|
|
8
|
+
*
|
|
9
|
+
* Main thread:
|
|
10
|
+
* - `createTableWorker` — one shared handle per table worker
|
|
11
|
+
* - `createWorkerRowModel` — turns any flat row model stage into a
|
|
12
|
+
* worker-backed factory for the matching `features` slot
|
|
13
|
+
* - `workerRowModelsFeature` — registers the `workerRowModels` state slice
|
|
14
|
+
*
|
|
15
|
+
* Worker entry (user-authored file):
|
|
16
|
+
* - `initTableWorker` — runs the shadow table; computes only the stages whose
|
|
17
|
+
* row model factories are registered in its config
|
|
18
|
+
*/
|
|
19
|
+
export * from './worker/tableWorkerProtocol'
|
|
20
|
+
export * from './worker/initTableWorker'
|
|
21
|
+
export * from './worker/createTableWorker'
|
|
22
|
+
export * from './worker/createWorkerRowModel'
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { table_autoResetPageIndex } from '../features/row-pagination/rowPaginationFeature.utils'
|
|
2
|
+
import { table_autoResetExpanded } from '../features/row-expanding/rowExpandingFeature.utils'
|
|
3
|
+
import {
|
|
4
|
+
tableWorkerPipeline,
|
|
5
|
+
tableWorkerStageStateDeps,
|
|
6
|
+
} from './tableWorkerProtocol'
|
|
7
|
+
import type { Table_Internal } from '../types/Table'
|
|
8
|
+
import type { TableFeature } from '../types/TableFeatures'
|
|
9
|
+
import type { TableWorkerDataPayload } from './rebuildRowModel'
|
|
10
|
+
import type {
|
|
11
|
+
TableState_WorkerRowModels,
|
|
12
|
+
TableWorkerResponse,
|
|
13
|
+
TableWorkerStage,
|
|
14
|
+
TableWorkerStagePayload,
|
|
15
|
+
} from './tableWorkerProtocol'
|
|
16
|
+
|
|
17
|
+
// Importing anything from this module (e.g. `workerRowModelsFeature`)
|
|
18
|
+
// registers the plugin key and its state slice with the core type maps, so
|
|
19
|
+
// userland needs no `declare module` of its own. Apps that never use worker
|
|
20
|
+
// row models never load this module and never see the types.
|
|
21
|
+
declare module '../types/TableFeatures' {
|
|
22
|
+
interface Plugins {
|
|
23
|
+
workerRowModelsFeature: TableFeature
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
declare module '../types/TableState' {
|
|
27
|
+
interface TableState_FeatureMap {
|
|
28
|
+
workerRowModelsFeature: TableState_WorkerRowModels
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface TableWorkerOptions {
|
|
33
|
+
/**
|
|
34
|
+
* Creates the dedicated worker that runs the shadow table. The worker entry
|
|
35
|
+
* must call `initTableWorker` with the same columns and processing config.
|
|
36
|
+
*
|
|
37
|
+
* The `new Worker(new URL(...))` expression must live in your code (not the
|
|
38
|
+
* library) so your bundler can statically discover and bundle the worker
|
|
39
|
+
* entry file.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* createWorker: () =>
|
|
44
|
+
* new Worker(new URL('./table.worker.ts', import.meta.url), {
|
|
45
|
+
* type: 'module',
|
|
46
|
+
* })
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
createWorker: () => Worker
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface TableWorkerBridge {
|
|
53
|
+
worker: Worker | null
|
|
54
|
+
/** The worker errored (load failure or uncaught throw); stop posting. */
|
|
55
|
+
failed: boolean
|
|
56
|
+
lastData: unknown
|
|
57
|
+
dataVersion: number
|
|
58
|
+
requestId: number
|
|
59
|
+
resultRequestId: number
|
|
60
|
+
/** A process request has been posted and its result has not arrived yet. */
|
|
61
|
+
inFlight: boolean
|
|
62
|
+
/** State changed since the last posted request; post when possible. */
|
|
63
|
+
needsProcess: boolean
|
|
64
|
+
sentAt: number
|
|
65
|
+
/** The stages registered on this table (grows as factories initialize). */
|
|
66
|
+
stages: Set<TableWorkerStage>
|
|
67
|
+
/** Snapshot of state refs + stage count captured at the last post. */
|
|
68
|
+
sentState: Record<string, unknown> | null
|
|
69
|
+
sentStageCount: number
|
|
70
|
+
/** Latest observed state refs, posted on the trailing edge if in flight. */
|
|
71
|
+
lastState: Record<string, unknown>
|
|
72
|
+
results: { [K in TableWorkerStage]?: TableWorkerDataPayload }
|
|
73
|
+
/** Bumped per stage only when that stage's payload actually changed. */
|
|
74
|
+
stageVersions: { [K in TableWorkerStage]?: number }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
type AnyTable = Table_Internal<any, any>
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A handle shared by every worker-backed row model on a table. It owns the
|
|
81
|
+
* worker instance and the per-table request/result bookkeeping, so registering
|
|
82
|
+
* one stage or four costs exactly one worker and one round trip per change.
|
|
83
|
+
*/
|
|
84
|
+
export interface TableWorker {
|
|
85
|
+
_options: TableWorkerOptions
|
|
86
|
+
_bridges: WeakMap<object, TableWorkerBridge>
|
|
87
|
+
_liveBridges: Set<TableWorkerBridge>
|
|
88
|
+
/**
|
|
89
|
+
* Terminates every worker created through this handle and resets the
|
|
90
|
+
* bookkeeping. Safe to call at any time: the next row model read lazily
|
|
91
|
+
* recreates the worker and re-sends the data (self-healing). Note that
|
|
92
|
+
* nothing calls this automatically yet; React StrictMode double-mounts and
|
|
93
|
+
* HMR updates still leak a worker in development until the reactivity
|
|
94
|
+
* bindings grow a real `unmount` hook.
|
|
95
|
+
*/
|
|
96
|
+
terminate: () => void
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Registers the `workerRowModels` state slice
|
|
101
|
+
* (`{ version, isPending, lastComputeMs, lastRoundTripMs }`). Worker results
|
|
102
|
+
* land by bumping `version`, so re-renders flow through the exact same state
|
|
103
|
+
* mechanism as every other table state change.
|
|
104
|
+
*/
|
|
105
|
+
export const workerRowModelsFeature: TableFeature = {
|
|
106
|
+
getInitialState: (initialState: any) => ({
|
|
107
|
+
workerRowModels: { version: 0, isPending: false },
|
|
108
|
+
...initialState,
|
|
109
|
+
}),
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Creates the shared worker handle for a table's worker-backed row models.
|
|
114
|
+
* Pass it to `createWorkerRowModel()` once per stage you want offloaded.
|
|
115
|
+
*/
|
|
116
|
+
export function createTableWorker(options: TableWorkerOptions): TableWorker {
|
|
117
|
+
const liveBridges = new Set<TableWorkerBridge>()
|
|
118
|
+
return {
|
|
119
|
+
_options: options,
|
|
120
|
+
_bridges: new WeakMap(),
|
|
121
|
+
_liveBridges: liveBridges,
|
|
122
|
+
terminate: () => {
|
|
123
|
+
for (const bridge of liveBridges) {
|
|
124
|
+
bridge.worker?.terminate()
|
|
125
|
+
bridge.worker = null
|
|
126
|
+
bridge.failed = false
|
|
127
|
+
bridge.lastData = undefined
|
|
128
|
+
bridge.inFlight = false
|
|
129
|
+
bridge.needsProcess = true
|
|
130
|
+
bridge.sentState = null
|
|
131
|
+
bridge.sentStageCount = 0
|
|
132
|
+
}
|
|
133
|
+
liveBridges.clear()
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function getTableWorkerBridge(
|
|
139
|
+
tableWorker: TableWorker,
|
|
140
|
+
table: AnyTable,
|
|
141
|
+
): TableWorkerBridge {
|
|
142
|
+
let bridge = tableWorker._bridges.get(table)
|
|
143
|
+
if (!bridge) {
|
|
144
|
+
bridge = {
|
|
145
|
+
worker: null,
|
|
146
|
+
failed: false,
|
|
147
|
+
lastData: undefined,
|
|
148
|
+
dataVersion: 0,
|
|
149
|
+
requestId: 0,
|
|
150
|
+
resultRequestId: 0,
|
|
151
|
+
inFlight: false,
|
|
152
|
+
needsProcess: true,
|
|
153
|
+
sentAt: 0,
|
|
154
|
+
stages: new Set(),
|
|
155
|
+
sentState: null,
|
|
156
|
+
sentStageCount: 0,
|
|
157
|
+
lastState: {},
|
|
158
|
+
results: {},
|
|
159
|
+
stageVersions: {},
|
|
160
|
+
}
|
|
161
|
+
tableWorker._bridges.set(table, bridge)
|
|
162
|
+
}
|
|
163
|
+
return bridge
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Shallow reference comparison; atoms return stable refs when unchanged. */
|
|
167
|
+
function statesEqual(
|
|
168
|
+
a: Record<string, unknown> | null,
|
|
169
|
+
b: Record<string, unknown>,
|
|
170
|
+
): boolean {
|
|
171
|
+
if (a === null) return false
|
|
172
|
+
const aKeys = Object.keys(a)
|
|
173
|
+
const bKeys = Object.keys(b)
|
|
174
|
+
if (aKeys.length !== bKeys.length) return false
|
|
175
|
+
for (const key of bKeys) {
|
|
176
|
+
if (a[key] !== b[key]) return false
|
|
177
|
+
}
|
|
178
|
+
return true
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function setWorkerRowModelsState(
|
|
182
|
+
table: AnyTable,
|
|
183
|
+
update: (prev: any) => Record<string, unknown>,
|
|
184
|
+
) {
|
|
185
|
+
const stateAtom = (table.baseAtoms as Record<string, any>).workerRowModels
|
|
186
|
+
stateAtom?.set((prev: any) => update(prev ?? { version: 0 }))
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function postProcess(table: AnyTable, bridge: TableWorkerBridge): void {
|
|
190
|
+
const stages = tableWorkerPipeline.filter((stage) => bridge.stages.has(stage))
|
|
191
|
+
bridge.needsProcess = false
|
|
192
|
+
bridge.sentState = bridge.lastState
|
|
193
|
+
bridge.sentStageCount = bridge.stages.size
|
|
194
|
+
bridge.inFlight = true
|
|
195
|
+
bridge.sentAt = performance.now()
|
|
196
|
+
const requestId = ++bridge.requestId
|
|
197
|
+
bridge.worker!.postMessage({
|
|
198
|
+
type: 'process',
|
|
199
|
+
requestId,
|
|
200
|
+
dataVersion: bridge.dataVersion,
|
|
201
|
+
stages,
|
|
202
|
+
state: bridge.lastState,
|
|
203
|
+
})
|
|
204
|
+
// postProcess can run during render (via sync); defer the pending write.
|
|
205
|
+
table._reactivity.schedule(() => {
|
|
206
|
+
if (bridge.requestId === requestId && bridge.resultRequestId < requestId) {
|
|
207
|
+
setWorkerRowModelsState(table, (prev) => ({ ...prev, isPending: true }))
|
|
208
|
+
}
|
|
209
|
+
})
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function handleResult(
|
|
213
|
+
table: AnyTable,
|
|
214
|
+
bridge: TableWorkerBridge,
|
|
215
|
+
message: TableWorkerResponse,
|
|
216
|
+
) {
|
|
217
|
+
if (message.requestId !== bridge.requestId) return
|
|
218
|
+
bridge.inFlight = false
|
|
219
|
+
bridge.resultRequestId = message.requestId
|
|
220
|
+
|
|
221
|
+
// A data change raced this request: the result is for the old dataset.
|
|
222
|
+
// Drop it and immediately re-process against the new data.
|
|
223
|
+
if (message.dataVersion !== bridge.dataVersion) {
|
|
224
|
+
postProcess(table, bridge)
|
|
225
|
+
return
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Merge stage payloads: `unchanged` keeps the previous result (and its
|
|
229
|
+
// rebuilt model, via the per-stage version), changed payloads replace it.
|
|
230
|
+
let anyChanged = false
|
|
231
|
+
let groupedChanged = false
|
|
232
|
+
for (const [stage, payload] of Object.entries(message.stages) as Array<
|
|
233
|
+
[TableWorkerStage, TableWorkerStagePayload]
|
|
234
|
+
>) {
|
|
235
|
+
if (payload.kind === 'unchanged') continue
|
|
236
|
+
bridge.results[stage] = payload
|
|
237
|
+
bridge.stageVersions[stage] = (bridge.stageVersions[stage] ?? 0) + 1
|
|
238
|
+
anyChanged = true
|
|
239
|
+
if (stage === 'grouped') groupedChanged = true
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const roundTripMs = performance.now() - bridge.sentAt
|
|
243
|
+
setWorkerRowModelsState(table, (prev) => ({
|
|
244
|
+
version: (prev.version ?? 0) + 1,
|
|
245
|
+
isPending: false,
|
|
246
|
+
lastComputeMs: message.computeMs,
|
|
247
|
+
lastRoundTripMs: roundTripMs,
|
|
248
|
+
}))
|
|
249
|
+
|
|
250
|
+
// The async equivalent of the sync models' `onAfterUpdate` hooks. The
|
|
251
|
+
// worker's unchanged-detection is its memo identity, so `groupedChanged`
|
|
252
|
+
// mirrors exactly when the sync grouped model would have recomputed (and
|
|
253
|
+
// reset expansion).
|
|
254
|
+
if (anyChanged) {
|
|
255
|
+
table._reactivity.schedule(() =>
|
|
256
|
+
table._reactivity.untrack(() => {
|
|
257
|
+
if (groupedChanged) {
|
|
258
|
+
table_autoResetExpanded(table)
|
|
259
|
+
}
|
|
260
|
+
table_autoResetPageIndex(table)
|
|
261
|
+
}),
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Trailing edge: state changed while this request was in flight.
|
|
266
|
+
if (bridge.needsProcess) {
|
|
267
|
+
postProcess(table, bridge)
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function handleError(
|
|
272
|
+
table: AnyTable,
|
|
273
|
+
bridge: TableWorkerBridge,
|
|
274
|
+
event: unknown,
|
|
275
|
+
) {
|
|
276
|
+
if (bridge.failed) return
|
|
277
|
+
bridge.failed = true
|
|
278
|
+
bridge.inFlight = false
|
|
279
|
+
console.error(
|
|
280
|
+
'[table-worker] The table worker failed; worker row models will keep ' +
|
|
281
|
+
'their last results and stop updating. Check that the worker entry ' +
|
|
282
|
+
'loads and that its initTableWorker() config is thread-portable.',
|
|
283
|
+
event,
|
|
284
|
+
)
|
|
285
|
+
bridge.worker?.terminate()
|
|
286
|
+
bridge.worker = null
|
|
287
|
+
setWorkerRowModelsState(table, (prev) => ({ ...prev, isPending: false }))
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function ensureWorker(
|
|
291
|
+
tableWorker: TableWorker,
|
|
292
|
+
table: AnyTable,
|
|
293
|
+
bridge: TableWorkerBridge,
|
|
294
|
+
) {
|
|
295
|
+
if (bridge.worker) return
|
|
296
|
+
bridge.worker = tableWorker._options.createWorker()
|
|
297
|
+
tableWorker._liveBridges.add(bridge)
|
|
298
|
+
bridge.worker.onmessage = (event: MessageEvent<TableWorkerResponse>) => {
|
|
299
|
+
handleResult(table, bridge, event.data)
|
|
300
|
+
}
|
|
301
|
+
bridge.worker.onerror = (event) => handleError(table, bridge, event)
|
|
302
|
+
bridge.worker.onmessageerror = (event) => handleError(table, bridge, event)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Pull-based sync, called at the top of every worker-backed row model read
|
|
307
|
+
* (i.e. every render). Posts data on identity change and a single-flight
|
|
308
|
+
* process request on state change; both are cheap no-ops otherwise, and
|
|
309
|
+
* multiple stages sharing the handle dedupe onto one request.
|
|
310
|
+
*/
|
|
311
|
+
export function syncTableWorker(tableWorker: TableWorker, table: AnyTable) {
|
|
312
|
+
// SSR: no Worker global. Getters fall back to pre-stage models, so the
|
|
313
|
+
// server renders unprocessed rows and the client takes over after hydration.
|
|
314
|
+
if (typeof Worker === 'undefined') return
|
|
315
|
+
|
|
316
|
+
const bridge = getTableWorkerBridge(tableWorker, table)
|
|
317
|
+
if (bridge.failed) return
|
|
318
|
+
ensureWorker(tableWorker, table, bridge)
|
|
319
|
+
|
|
320
|
+
const data = table.options.data
|
|
321
|
+
if (data !== bridge.lastData) {
|
|
322
|
+
bridge.lastData = data
|
|
323
|
+
bridge.dataVersion++
|
|
324
|
+
bridge.worker!.postMessage({
|
|
325
|
+
type: 'data',
|
|
326
|
+
dataVersion: bridge.dataVersion,
|
|
327
|
+
data,
|
|
328
|
+
})
|
|
329
|
+
bridge.needsProcess = true
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Union of the registered stages' state deps, compared by reference (atoms
|
|
333
|
+
// return stable refs when a slice did not change).
|
|
334
|
+
const atoms = table.atoms as Record<string, any>
|
|
335
|
+
const state: Record<string, unknown> = {}
|
|
336
|
+
for (const stage of bridge.stages) {
|
|
337
|
+
for (const key of tableWorkerStageStateDeps[stage]) {
|
|
338
|
+
state[key] = atoms[key]?.get()
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
bridge.lastState = state
|
|
342
|
+
|
|
343
|
+
if (
|
|
344
|
+
!bridge.needsProcess &&
|
|
345
|
+
(!statesEqual(bridge.sentState, state) ||
|
|
346
|
+
bridge.stages.size !== bridge.sentStageCount)
|
|
347
|
+
) {
|
|
348
|
+
bridge.needsProcess = true
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// Single-flight: at most one request in the worker at a time. If one is in
|
|
352
|
+
// flight, the latest state is posted from the result handler (trailing
|
|
353
|
+
// edge), so rapid input coalesces instead of queueing doomed computes.
|
|
354
|
+
if (bridge.needsProcess && !bridge.inFlight) {
|
|
355
|
+
postProcess(table, bridge)
|
|
356
|
+
}
|
|
357
|
+
}
|