MCPcopy
hub / github.com/TanStack/table / createSvelteTable

Function createSvelteTable

packages/svelte-table/src/index.ts:71–125  ·  view source on GitHub ↗
(
  options: ReadableOrVal<TableOptions<TData>>
)

Source from the content-addressed store, hash-verified

69type ReadableOrVal<T> = T | Readable<T>
70
71export function createSvelteTable<TData extends RowData>(
72 options: ReadableOrVal<TableOptions<TData>>
73) {
74 let optionsStore: Readable<TableOptions<TData>>
75
76 if ('subscribe' in options) {
77 optionsStore = options
78 } else {
79 optionsStore = readable(options)
80 }
81
82 let resolvedOptions: TableOptionsResolved<TData> = {
83 state: {}, // Dummy state
84 onStateChange: () => {}, // noop
85 renderFallbackValue: null,
86 ...get(optionsStore),
87 }
88
89 let table = createTable(resolvedOptions)
90
91 let stateStore = writable(/** @type {number} */ table.initialState)
92 // combine stores
93 let stateOptionsStore = derived([stateStore, optionsStore], s => s)
94 const tableReadable = readable(table, function start(set) {
95 const unsubscribe = stateOptionsStore.subscribe(([state, options]) => {
96 table.setOptions(prev => {
97 return {
98 ...prev,
99 ...options,
100 state: { ...state, ...options.state },
101 // Similarly, we'll maintain both our internal state and any user-provided
102 // state.
103 onStateChange: updater => {
104 if (updater instanceof Function) {
105 stateStore.update(updater)
106 } else {
107 stateStore.set(updater)
108 }
109
110 resolvedOptions.onStateChange?.(updater)
111 },
112 }
113 })
114
115 // it didn't seem to rerender without setting the table
116 set(table)
117 })
118
119 return function stop() {
120 unsubscribe()
121 }
122 })
123
124 return tableReadable
125}

Callers

nothing calls this directly

Calls 3

createTableFunction · 0.90
getFunction · 0.50
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…