@tanstack/react-table 8.0.0-alpha.7 → 8.0.0-alpha.8
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/build/cjs/core.js +19 -11
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/createTable.js +9 -23
- package/build/cjs/createTable.js.map +1 -1
- package/build/esm/index.js +28 -34
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +245 -231
- package/build/types/core.d.ts +3 -2
- package/build/umd/index.development.js +31 -38
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +7 -1
- package/src/core.tsx +16 -11
- package/src/createTable.tsx +9 -29
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-table",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "8.0.0-alpha.
|
|
4
|
+
"version": "8.0.0-alpha.8",
|
|
5
5
|
"description": "Hooks for building lightweight, fast and extendable datagrids for React",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/tanstack/react-table#readme",
|
|
@@ -36,5 +36,11 @@
|
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"react": ">=16",
|
|
38
38
|
"react-dom": ">=16"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"use-sync-external-store": "^1.0.0-rc.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/use-sync-external-store": "^0.0.3"
|
|
39
45
|
}
|
|
40
46
|
}
|
package/src/core.tsx
CHANGED
|
@@ -84,7 +84,8 @@ export type CoreOptions<
|
|
|
84
84
|
|
|
85
85
|
export type TableCore<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
|
|
86
86
|
{
|
|
87
|
-
|
|
87
|
+
subscribe: (cb: () => void) => () => void
|
|
88
|
+
notify: () => void
|
|
88
89
|
initialState: TableState
|
|
89
90
|
internalState: TableState
|
|
90
91
|
reset: () => void
|
|
@@ -360,8 +361,7 @@ export function createTableInstance<
|
|
|
360
361
|
TSortingFns,
|
|
361
362
|
TAggregationFns
|
|
362
363
|
>(
|
|
363
|
-
options: Options<TData, TValue, TFilterFns, TSortingFns, TAggregationFns
|
|
364
|
-
rerender: () => void
|
|
364
|
+
options: Options<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
365
365
|
): ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
|
|
366
366
|
if (process.env.NODE_ENV !== 'production' && options.debug) {
|
|
367
367
|
console.info('Creating React Table Instance...')
|
|
@@ -375,6 +375,8 @@ export function createTableInstance<
|
|
|
375
375
|
TAggregationFns
|
|
376
376
|
>
|
|
377
377
|
|
|
378
|
+
let listeners: (() => void)[] = []
|
|
379
|
+
|
|
378
380
|
const defaultOptions = features.reduce((obj, feature) => {
|
|
379
381
|
return Object.assign(obj, (feature as any).getDefaultOptions?.(instance))
|
|
380
382
|
}, {})
|
|
@@ -406,10 +408,18 @@ export function createTableInstance<
|
|
|
406
408
|
TAggregationFns
|
|
407
409
|
> = {
|
|
408
410
|
...instance,
|
|
411
|
+
subscribe: cb => {
|
|
412
|
+
listeners.push(cb)
|
|
413
|
+
return () => {
|
|
414
|
+
listeners = listeners.filter(l => l !== cb)
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
notify: () => {
|
|
418
|
+
listeners.forEach(l => l())
|
|
419
|
+
},
|
|
409
420
|
...features.reduce((obj, feature) => {
|
|
410
421
|
return Object.assign(obj, (feature as any).getInstance?.(instance))
|
|
411
422
|
}, {}),
|
|
412
|
-
rerender,
|
|
413
423
|
initialState,
|
|
414
424
|
internalState: initialState,
|
|
415
425
|
reset: () => {
|
|
@@ -434,10 +444,7 @@ export function createTableInstance<
|
|
|
434
444
|
return state
|
|
435
445
|
},
|
|
436
446
|
|
|
437
|
-
setState: (
|
|
438
|
-
updater: Updater<TableState>,
|
|
439
|
-
shouldRerender: boolean = true
|
|
440
|
-
) => {
|
|
447
|
+
setState: (updater: Updater<TableState>) => {
|
|
441
448
|
const onStateChange = instance.options.onStateChange
|
|
442
449
|
|
|
443
450
|
let internalState = instance.internalState
|
|
@@ -450,9 +457,7 @@ export function createTableInstance<
|
|
|
450
457
|
return
|
|
451
458
|
}
|
|
452
459
|
|
|
453
|
-
|
|
454
|
-
instance.rerender()
|
|
455
|
-
}
|
|
460
|
+
instance.notify()
|
|
456
461
|
},
|
|
457
462
|
|
|
458
463
|
getDefaultColumn: memo(
|
package/src/createTable.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim'
|
|
2
3
|
import { Cell, Column, Row } from '.'
|
|
3
4
|
import { createTableInstance } from './core'
|
|
4
5
|
import {
|
|
@@ -222,42 +223,21 @@ export function createTable<
|
|
|
222
223
|
useTable: <TData, TValue, TFilterFns, TSortingFns, TAggregationFns>(
|
|
223
224
|
options: Options<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
224
225
|
): ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> => {
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
>(undefined!)
|
|
228
|
-
|
|
229
|
-
const unsafeRerender = React.useReducer(() => ({}), {})[1]
|
|
230
|
-
|
|
231
|
-
const isMountedRef = React.useRef(false)
|
|
232
|
-
|
|
233
|
-
const rerender = React.useCallback(() => {
|
|
234
|
-
if (!isMountedRef.current) {
|
|
235
|
-
return
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
unsafeRerender()
|
|
239
|
-
}, [])
|
|
240
|
-
|
|
241
|
-
React.useLayoutEffect(() => {
|
|
242
|
-
isMountedRef.current = true
|
|
243
|
-
return () => {
|
|
244
|
-
isMountedRef.current = false
|
|
245
|
-
}
|
|
246
|
-
})
|
|
247
|
-
|
|
248
|
-
if (!instanceRef.current) {
|
|
249
|
-
instanceRef.current = createTableInstance<
|
|
226
|
+
const [instance] = React.useState(() =>
|
|
227
|
+
createTableInstance<
|
|
250
228
|
TData,
|
|
251
229
|
TValue,
|
|
252
230
|
TFilterFns,
|
|
253
231
|
TSortingFns,
|
|
254
232
|
TAggregationFns
|
|
255
|
-
>(options
|
|
256
|
-
|
|
233
|
+
>(options)
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
useSyncExternalStore(instance.subscribe, () => instance.internalState)
|
|
257
237
|
|
|
258
|
-
|
|
238
|
+
instance.updateOptions(options)
|
|
259
239
|
|
|
260
|
-
return
|
|
240
|
+
return instance
|
|
261
241
|
},
|
|
262
242
|
types: undefined as any,
|
|
263
243
|
} as TableHelper<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|