( options: TableOptionsResolved<TData>, )
| 281 | } |
| 282 | |
| 283 | export function createTable<TData extends RowData>( |
| 284 | options: TableOptionsResolved<TData>, |
| 285 | ): Table<TData> { |
| 286 | if ( |
| 287 | process.env.NODE_ENV !== 'production' && |
| 288 | (options.debugAll || options.debugTable) |
| 289 | ) { |
| 290 | console.info('Creating Table Instance...') |
| 291 | } |
| 292 | |
| 293 | const _features = [...builtInFeatures, ...(options._features ?? [])] |
| 294 | |
| 295 | let table = { _features } as unknown as Table<TData> |
| 296 | |
| 297 | const defaultOptions = table._features.reduce((obj, feature) => { |
| 298 | return Object.assign(obj, feature.getDefaultOptions?.(table)) |
| 299 | }, {}) as TableOptionsResolved<TData> |
| 300 | |
| 301 | const mergeOptions = (options: TableOptionsResolved<TData>) => { |
| 302 | if (table.options.mergeOptions) { |
| 303 | return table.options.mergeOptions(defaultOptions, options) |
| 304 | } |
| 305 | |
| 306 | return { |
| 307 | ...defaultOptions, |
| 308 | ...options, |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | const coreInitialState: CoreTableState = {} |
| 313 | |
| 314 | let initialState = { |
| 315 | ...coreInitialState, |
| 316 | ...(options.initialState ?? {}), |
| 317 | } as TableState |
| 318 | |
| 319 | table._features.forEach((feature) => { |
| 320 | initialState = (feature.getInitialState?.(initialState) ?? |
| 321 | initialState) as TableState |
| 322 | }) |
| 323 | |
| 324 | const queued: (() => void)[] = [] |
| 325 | let queuedTimeout = false |
| 326 | |
| 327 | const coreInstance: CoreInstance<TData> = { |
| 328 | _features, |
| 329 | options: { |
| 330 | ...defaultOptions, |
| 331 | ...options, |
| 332 | }, |
| 333 | initialState, |
| 334 | _queue: (cb) => { |
| 335 | queued.push(cb) |
| 336 | |
| 337 | if (!queuedTimeout) { |
| 338 | queuedTimeout = true |
| 339 | |
| 340 | // Schedule a microtask to run the queued callbacks after |
no test coverage detected