@tanstack/svelte-table 9.0.0-alpha.49 → 9.0.0-alpha.50

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.
@@ -1,7 +1,7 @@
1
1
  import { constructTable } from '@tanstack/table-core';
2
2
  import { useSelector } from '@tanstack/svelte-store';
3
3
  import { untrack } from 'svelte';
4
- import { mergeObjects } from './merge-objects';
4
+ import { flatMerge, mergeObjects } from './merge-objects';
5
5
  import { svelteReactivity } from './reactivity.svelte';
6
6
  /**
7
7
  * Creates a Svelte 5 table instance backed by rune-aware TanStack Store atoms.
@@ -39,7 +39,7 @@ export function createTable(tableOptions, selector) {
39
39
  // 2. Set up resolved options with mergeOptions handler
40
40
  const resolvedOptions = mergeObjects({
41
41
  mergeOptions: (defaultOptions, newOptions) => {
42
- return mergeObjects(defaultOptions, newOptions);
42
+ return flatMerge(defaultOptions, newOptions);
43
43
  },
44
44
  }, mergedOptions);
45
45
  // 3. Construct table
@@ -62,7 +62,7 @@ export function createTable(tableOptions, selector) {
62
62
  void mergedOptions.data;
63
63
  untrack(() => {
64
64
  table.setOptions((prev) => {
65
- return mergeObjects(prev, mergedOptions);
65
+ return flatMerge(prev, mergedOptions);
66
66
  });
67
67
  });
68
68
  });
@@ -6,3 +6,19 @@ export declare function mergeObjects<T>(source: T): T;
6
6
  export declare function mergeObjects<T, U>(source: T, source1: U): T & U;
7
7
  export declare function mergeObjects<T, U, V>(source: T, source1: U, source2: V): T & U & V;
8
8
  export declare function mergeObjects<T, U, V, W>(source: T, source1: U, source2: V, source3: W): T & U & V & W;
9
+ /**
10
+ * Merges objects together by eagerly resolving all values into a flat object.
11
+ *
12
+ * Unlike `mergeObjects`, this does NOT preserve getters — values are read once
13
+ * and stored as plain data properties. This prevents the getter-chain
14
+ * accumulation that causes O(N) lookups when the result is repeatedly passed
15
+ * back as a source in subsequent merges (e.g., inside `$effect.pre` loops).
16
+ *
17
+ * Later sources take precedence; `undefined` values do not override.
18
+ *
19
+ * @see https://github.com/TanStack/table/issues/6235
20
+ */
21
+ export declare function flatMerge<T>(source: T): T;
22
+ export declare function flatMerge<T, U>(source: T, source1: U): T & U;
23
+ export declare function flatMerge<T, U, V>(source: T, source1: U, source2: V): T & U & V;
24
+ export declare function flatMerge<T, U, V, W>(source: T, source1: U, source2: V, source3: W): T & U & V & W;
@@ -27,3 +27,19 @@ export function mergeObjects(...sources) {
27
27
  }
28
28
  return target;
29
29
  }
30
+ export function flatMerge(...sources) {
31
+ const result = {};
32
+ for (let source of sources) {
33
+ if (typeof source === 'function')
34
+ source = source();
35
+ if (!source)
36
+ continue;
37
+ for (const key of Reflect.ownKeys(source)) {
38
+ const value = source[key];
39
+ if (value !== undefined) {
40
+ result[key] = value;
41
+ }
42
+ }
43
+ }
44
+ return result;
45
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/svelte-table",
3
- "version": "9.0.0-alpha.49",
3
+ "version": "9.0.0-alpha.50",
4
4
  "description": "Headless UI for building powerful tables & datagrids for Svelte.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -1,7 +1,7 @@
1
1
  import { constructTable } from '@tanstack/table-core'
2
2
  import { useSelector } from '@tanstack/svelte-store'
3
3
  import { untrack } from 'svelte'
4
- import { mergeObjects } from './merge-objects'
4
+ import { flatMerge, mergeObjects } from './merge-objects'
5
5
  import { svelteReactivity } from './reactivity.svelte'
6
6
  import type {
7
7
  RowData,
@@ -75,7 +75,7 @@ export function createTable<
75
75
  defaultOptions: TableOptions<TFeatures, TData>,
76
76
  newOptions: Partial<TableOptions<TFeatures, TData>>,
77
77
  ) => {
78
- return mergeObjects(defaultOptions, newOptions)
78
+ return flatMerge(defaultOptions, newOptions)
79
79
  },
80
80
  },
81
81
  mergedOptions,
@@ -107,7 +107,7 @@ export function createTable<
107
107
 
108
108
  untrack(() => {
109
109
  table.setOptions((prev) => {
110
- return mergeObjects(prev, mergedOptions)
110
+ return flatMerge(prev, mergedOptions)
111
111
  })
112
112
  })
113
113
  })
@@ -41,3 +41,39 @@ export function mergeObjects(...sources: any): any {
41
41
  }
42
42
  return target
43
43
  }
44
+
45
+ /**
46
+ * Merges objects together by eagerly resolving all values into a flat object.
47
+ *
48
+ * Unlike `mergeObjects`, this does NOT preserve getters — values are read once
49
+ * and stored as plain data properties. This prevents the getter-chain
50
+ * accumulation that causes O(N) lookups when the result is repeatedly passed
51
+ * back as a source in subsequent merges (e.g., inside `$effect.pre` loops).
52
+ *
53
+ * Later sources take precedence; `undefined` values do not override.
54
+ *
55
+ * @see https://github.com/TanStack/table/issues/6235
56
+ */
57
+ export function flatMerge<T>(source: T): T
58
+ export function flatMerge<T, U>(source: T, source1: U): T & U
59
+ export function flatMerge<T, U, V>(source: T, source1: U, source2: V): T & U & V
60
+ export function flatMerge<T, U, V, W>(
61
+ source: T,
62
+ source1: U,
63
+ source2: V,
64
+ source3: W,
65
+ ): T & U & V & W
66
+ export function flatMerge(...sources: any): any {
67
+ const result: Record<PropertyKey, unknown> = {}
68
+ for (let source of sources) {
69
+ if (typeof source === 'function') source = source()
70
+ if (!source) continue
71
+ for (const key of Reflect.ownKeys(source)) {
72
+ const value = (source as Record<PropertyKey, unknown>)[key]
73
+ if (value !== undefined) {
74
+ result[key as string] = value
75
+ }
76
+ }
77
+ }
78
+ return result
79
+ }