Skip to content

Commit 6c7b95f

Browse files
committed
chore: update docs
1 parent 965415c commit 6c7b95f

4 files changed

Lines changed: 44 additions & 7 deletions

File tree

packages/docs/pages/api-reference/table.mdx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,15 @@ function MyComponent() {
164164

165165
### Cell Updates
166166

167+
**Note**: The `sync` function used in the examples below should be obtained from the `connector` as shown in the "Using Table References" section above.
168+
167169
#### `update(args: { diff: CellsByAddressType; historicize?: boolean; partial?: boolean; updateChangedTime?: boolean; reflection?: StorePatchType }): UserTable`
168170
Updates multiple cells at once.
169171

170172
```tsx
173+
// Get sync from connector
174+
const { table, sync } = connector.current.tableManager;
175+
171176
const newTable = table.update({
172177
diff: {
173178
'A1': { value: 'Updated Value' },
@@ -182,6 +187,9 @@ sync(newTable); // Required to apply changes
182187
Writes a value to a specific cell.
183188

184189
```tsx
190+
// Get sync from connector
191+
const { table, sync } = connector.current.tableManager;
192+
185193
const newTable = table.write({
186194
point: { x: 1, y: 1 },
187195
value: 'Hello World'
@@ -193,6 +201,9 @@ sync(newTable); // Required to apply changes
193201
Writes a matrix of values starting at a specific point.
194202

195203
```tsx
204+
// Get sync from connector
205+
const { table, sync } = connector.current.tableManager;
206+
196207
const newTable = table.writeMatrix({
197208
point: { x: 1, y: 1 },
198209
matrix: [['A1', 'B1'], ['A2', 'B2']]
@@ -207,6 +218,9 @@ sync(newTable); // Required to apply changes
207218
Inserts rows at the specified position. If `diff` is provided, it also updates the cells after insertion.
208219

209220
```tsx
221+
// Get sync from connector
222+
const { table, sync } = connector.current.tableManager;
223+
210224
const newTable = table.insertRows({
211225
y: 5,
212226
numRows: 2,
@@ -216,12 +230,16 @@ const newTable = table.insertRows({
216230
A6: { value: 'New Row 2' },
217231
},
218232
});
233+
sync(newTable); // Required to apply changes
219234
```
220235

221236
#### `removeRows(args: { y: number; numRows: number; reflection?: StorePatchType }): UserTable`
222237
Removes rows at a specific position.
223238

224239
```tsx
240+
// Get sync from connector
241+
const { table, sync } = connector.current.tableManager;
242+
225243
const newTable = table.removeRows({
226244
y: 2,
227245
numRows: 3
@@ -236,6 +254,9 @@ sync(newTable); // Required to apply changes
236254
Inserts columns at the specified position. If `diff` is provided, it also updates the cells after insertion.
237255

238256
```tsx
257+
// Get sync from connector
258+
const { table, sync } = connector.current.tableManager;
259+
239260
const newTable = table.insertCols({
240261
x: 3,
241262
numCols: 2,
@@ -245,12 +266,16 @@ const newTable = table.insertCols({
245266
D1: { value: 'New Col 2' },
246267
},
247268
});
269+
sync(newTable); // Required to apply changes
248270
```
249271

250272
#### `removeCols(args: { x: number; numCols: number; reflection?: StorePatchType }): UserTable`
251273
Removes columns at a specific position.
252274

253275
```tsx
276+
// Get sync from connector
277+
const { table, sync } = connector.current.tableManager;
278+
254279
const newTable = table.removeCols({
255280
x: 2,
256281
numCols: 3
@@ -264,6 +289,9 @@ sync(newTable); // Required to apply changes
264289
Moves cells from one area to another.
265290

266291
```tsx
292+
// Get sync from connector
293+
const { table, sync } = connector.current.tableManager;
294+
267295
const newTable = table.move({
268296
src: { top: 0, left: 0, bottom: 2, right: 2 },
269297
dst: { top: 5, left: 5, bottom: 7, right: 7 }
@@ -275,6 +303,9 @@ sync(newTable); // Required to apply changes
275303
Copies cells from one area to another.
276304

277305
```tsx
306+
// Get sync from connector
307+
const { table, sync } = connector.current.tableManager;
308+
278309
const newTable = table.copy({
279310
src: { top: 0, left: 0, bottom: 2, right: 2 },
280311
dst: { top: 5, left: 5, bottom: 7, right: 7 },
@@ -289,6 +320,9 @@ sync(newTable); // Required to apply changes
289320
Sorts all data rows by the values in the specified column. Supports ascending and descending order. Null/undefined values are sorted to the end. This operation is recorded in the undo/redo history.
290321

291322
```tsx
323+
// Get sync from connector
324+
const { table, sync } = connector.current.tableManager;
325+
292326
// Sort by column B ascending
293327
const newTable = table.sortRows({ x: 2, direction: 'asc' });
294328
sync(newTable);
@@ -332,6 +366,9 @@ Available filter methods:
332366
| `notEmpty` | Cell is not empty (no value required) |
333367

334368
```tsx
369+
// Get sync from connector
370+
const { table, sync } = connector.current.tableManager;
371+
335372
// Filter column B: show only rows where value > 80
336373
const newTable = table.filterRows({
337374
x: 2,

packages/react-core/src/components/Cell.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const Cell: FC<Props> = memo(({ y, x }) => {
3838

3939
const cellRef = useRef<HTMLTableCellElement>(null);
4040
const {
41-
tableReactive: tableRef,
41+
tableReactive,
4242
editingAddress,
4343
choosing,
4444
selectingZone,
@@ -49,7 +49,7 @@ export const Cell: FC<Props> = memo(({ y, x }) => {
4949
autofillDraggingTo,
5050
contextMenuItems,
5151
} = store;
52-
const table = tableRef.current;
52+
const table = tableReactive.current;
5353

5454
// Whether the focus is on another sheet
5555
const xSheetFocused = isXSheetFocused(store);

packages/react-core/src/formula/functions/__async.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ export const getAsyncCache = (
116116
*
117117
* @param ttlMilliseconds - Cache time-to-live in **milliseconds**. undefined = never expires.
118118
*/
119-
export const getOrSaveAsyncCache = (
119+
export const awaitAndSave = (
120120
promise: Promise<any>,
121121
table: { wire: Wire; getId: (p: PointType) => string },
122122
origin: PointType,
123123
key: string,
124124
ttlMilliseconds?: number,
125-
): any => {
125+
): Pending => {
126126
const cellId = table.getId(origin);
127127
const wire = table.wire;
128128

packages/react-core/src/formula/functions/__base.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Expression } from '../evaluator';
44
import {
55
hasPendingArg,
66
buildAsyncCacheKey,
7-
getOrSaveAsyncCache,
7+
awaitAndSave,
88
createPropagatedPending,
99
getAsyncCache,
1010
asyncCacheMiss,
@@ -57,8 +57,8 @@ export class BaseFunction {
5757
}
5858

5959
// @ts-expect-error main is not defined in BaseFunction
60-
const result = this.main(...this.bareArgs);
61-
return getOrSaveAsyncCache(result, this.table, this.origin!, key, this.ttlMilliseconds);
60+
const promise = this.main(...this.bareArgs);
61+
return awaitAndSave(promise, this.table, this.origin!, key, this.ttlMilliseconds);
6262
}
6363

6464
// For sync functions, just call and return

0 commit comments

Comments
 (0)